@bolttech/form-engine-core 1.0.2 → 1.0.4
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.d.ts +35 -6
- package/index.esm.js +38 -5
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -226,12 +226,21 @@ interface IFormSchema {
|
|
|
226
226
|
stopEventsOnSubmit?: boolean;
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
+
/**
|
|
230
|
+
* @type TFieldBinding
|
|
231
|
+
* settings from the field's location and value when valid.
|
|
232
|
+
*/
|
|
233
|
+
type TFieldBinding = {
|
|
234
|
+
path?: string;
|
|
235
|
+
value?: unknown;
|
|
236
|
+
};
|
|
229
237
|
/**
|
|
230
238
|
* @type TFormValues<T>
|
|
231
239
|
* Represents the values and state of a form. It has a generic type that allows the importer to determine which type values key will return.
|
|
232
240
|
*
|
|
233
241
|
* @property {Generic Type} values - The current values of the form fields.
|
|
234
242
|
* @property {string[]} erroredFields - A list of field names that have errors.
|
|
243
|
+
* @property {TFieldBinding} bindFields - A list of field names that have bind values with their path to submit.
|
|
235
244
|
* @property {boolean} isValid - Indicates whether the form is valid.
|
|
236
245
|
*
|
|
237
246
|
* @example
|
|
@@ -239,6 +248,7 @@ interface IFormSchema {
|
|
|
239
248
|
* const formValues: TFormValues = {
|
|
240
249
|
* values: { name: 'John', age: 30 },
|
|
241
250
|
* erroredFields: ['email'],
|
|
251
|
+
* bindFields: { path: 'field/name', value: 'John' },
|
|
242
252
|
* isValid: false
|
|
243
253
|
* };
|
|
244
254
|
* ```
|
|
@@ -247,6 +257,7 @@ type TFormValues<T> = {
|
|
|
247
257
|
values: T;
|
|
248
258
|
metadata: unknown;
|
|
249
259
|
erroredFields: string[];
|
|
260
|
+
bindFields?: TFieldBinding;
|
|
250
261
|
isValid: boolean;
|
|
251
262
|
};
|
|
252
263
|
/**
|
|
@@ -1396,6 +1407,7 @@ declare class FormField {
|
|
|
1396
1407
|
errorsString: string;
|
|
1397
1408
|
errorsList: string[];
|
|
1398
1409
|
private _props;
|
|
1410
|
+
private _adapterProps;
|
|
1399
1411
|
private _value;
|
|
1400
1412
|
private _stateValue;
|
|
1401
1413
|
private _metadata;
|
|
@@ -1455,7 +1467,7 @@ declare class FormField {
|
|
|
1455
1467
|
* @param {TMapper<unknown>} options.mapper, - component generic mapper containing render parameters for adapters
|
|
1456
1468
|
* @param {() => TFormValues<unknown>} options.getFormValues, - form instance function that builds onData parameter payload from fields
|
|
1457
1469
|
*/
|
|
1458
|
-
constructor({ formIndex, schemaComponent, config,
|
|
1470
|
+
constructor({ formIndex, schemaComponent, config, children, validateVisibility, resetValue, resetProperty, templateSubject$, fieldEventSubject$, dataSubject$, fieldValidNotification$, mountSubject$, mapper, getFormValues, submitEvent, visibility, persistValue, }: {
|
|
1459
1471
|
formIndex: string;
|
|
1460
1472
|
schemaComponent: IComponentSchema;
|
|
1461
1473
|
config?: TSchemaFormConfig;
|
|
@@ -1493,6 +1505,18 @@ declare class FormField {
|
|
|
1493
1505
|
* emissions to unsubscribed fields
|
|
1494
1506
|
*/
|
|
1495
1507
|
initializeObservers(): void;
|
|
1508
|
+
/**
|
|
1509
|
+
* Retrieves the raw props sent from the adapter.
|
|
1510
|
+
*
|
|
1511
|
+
* @returns {string} - raw props from the adapter
|
|
1512
|
+
*/
|
|
1513
|
+
get adapterProps(): string;
|
|
1514
|
+
/**
|
|
1515
|
+
* compares adapter props changes and emits the change if they effectively changed
|
|
1516
|
+
* preventing an emission from the adapter of the same props that can overwrite other prop
|
|
1517
|
+
* changes via templating
|
|
1518
|
+
*/
|
|
1519
|
+
set adapterProps(props: Record<string, unknown>);
|
|
1496
1520
|
/**
|
|
1497
1521
|
* Retrieves the properties associated with the form field.
|
|
1498
1522
|
*
|
|
@@ -2006,10 +2030,7 @@ declare class FormCore {
|
|
|
2006
2030
|
*
|
|
2007
2031
|
* @param {(payload: { field: string; data: TFormValues }) => void} callback callback function to call onData
|
|
2008
2032
|
*/
|
|
2009
|
-
subscribeData<T>(callback: (payload:
|
|
2010
|
-
field: string;
|
|
2011
|
-
data: TFormValues<T>;
|
|
2012
|
-
}) => void): Subscription;
|
|
2033
|
+
subscribeData<T>(callback: (payload: TFormOnDataEventPayload<T>) => void): Subscription;
|
|
2013
2034
|
/**
|
|
2014
2035
|
* method to register a callback function to be called when the form is valid
|
|
2015
2036
|
*
|
|
@@ -2296,6 +2317,14 @@ type TFormDataValues<T> = {
|
|
|
2296
2317
|
* Form Group onData event emitted payload on callback function parameter
|
|
2297
2318
|
*/
|
|
2298
2319
|
type TFormGroupOnDataEventPayload<T> = Record<string, TFormDataValues<T>>;
|
|
2320
|
+
/**
|
|
2321
|
+
* @type TFormOnDataEventPayload
|
|
2322
|
+
* Form onData event emitted payload on callback function parameter
|
|
2323
|
+
*/
|
|
2324
|
+
type TFormOnDataEventPayload<T> = {
|
|
2325
|
+
field: string;
|
|
2326
|
+
data: TFormValues<T>;
|
|
2327
|
+
};
|
|
2299
2328
|
/**
|
|
2300
2329
|
* @type TFormGroupOnValidEventPayload
|
|
2301
2330
|
* Form Group onValid event emitted payload on callback function parameter
|
|
@@ -2311,4 +2340,4 @@ type TFormGroupOnValidEventPayload = {
|
|
|
2311
2340
|
type TFormGroupOnSubmitEventPayload<T> = Record<string, TFormValues<T> | undefined>;
|
|
2312
2341
|
|
|
2313
2342
|
export { FormCore, FormField, FormGroup, TMutationEnum };
|
|
2314
|
-
export type { AllowOnly, IComponentSchema, IComponentSchemaAsFormField, IFormField, IFormSchema, IState, OneOf, TAllowedResetPropsMutationsEnum, TApiConfig, TApiEvent, TApiResponse, TApiResponsePayload, TAvailableValidations, TBetweenDatesValidation, TBetweenValidation, TCallbackValidation, TComponentPropsMapping, TConditionsValidation, TConditionsValidationSet, TCreditCardMatch, TCurrencyMask, TDateFormatsValidation, TDateInterval, TDateOperatorsValidation, TDateValidation, TDocumentValidation, TErrorMessages, TEvent, TEventDataProps, TEventDataPropsEnum, TEventEnum, TEventMessages, TEventMessagesValidationMethods, TEventProps, TEventPropsEnum, TEvents, TFieldEvent, TFieldValidationPayload, TFormCore, TFormDataPayload, TFormDataValues, TFormEntry, TFormGroup, TFormGroupOnDataEventPayload, TFormGroupOnSubmitEventPayload, TFormGroupOnValidEventPayload, TFormSubmitPayload, TFormValidationPayload, TFormValues, TFormatters, TGenericValidationRule, TLengthValidation, TMapper, TMaskGeneric, TMasks, TMultipleValidation, TMutationEvents, TProps, TResetPathMethods, TResetValueMethods, TSchemaFormConfig, TSchemaValidation, TSplitterFormatterValue, TSubscribedTemplates, TTemplateAvaliableScopes, TTemplateAvaliableScopesEnum, TTemplateEvent, TValidationHandler, TValidationMethods, TValidations, TValueChangeEvent, TVisibility };
|
|
2343
|
+
export type { AllowOnly, IComponentSchema, IComponentSchemaAsFormField, IFormField, IFormSchema, IState, OneOf, TAllowedResetPropsMutationsEnum, TApiConfig, TApiEvent, TApiResponse, TApiResponsePayload, TAvailableValidations, TBetweenDatesValidation, TBetweenValidation, TCallbackValidation, TComponentPropsMapping, TConditionsValidation, TConditionsValidationSet, TCreditCardMatch, TCurrencyMask, TDateFormatsValidation, TDateInterval, TDateOperatorsValidation, TDateValidation, TDocumentValidation, TErrorMessages, TEvent, TEventDataProps, TEventDataPropsEnum, TEventEnum, TEventMessages, TEventMessagesValidationMethods, TEventProps, TEventPropsEnum, TEvents, TFieldEvent, TFieldValidationPayload, TFormCore, TFormDataPayload, TFormDataValues, TFormEntry, TFormGroup, TFormGroupOnDataEventPayload, TFormGroupOnSubmitEventPayload, TFormGroupOnValidEventPayload, TFormOnDataEventPayload, TFormSubmitPayload, TFormValidationPayload, TFormValues, TFormatters, TGenericValidationRule, TLengthValidation, TMapper, TMaskGeneric, TMasks, TMultipleValidation, TMutationEvents, TProps, TResetPathMethods, TResetValueMethods, TSchemaFormConfig, TSchemaValidation, TSplitterFormatterValue, TSubscribedTemplates, TTemplateAvaliableScopes, TTemplateAvaliableScopesEnum, TTemplateEvent, TValidationHandler, TValidationMethods, TValidations, TValueChangeEvent, TVisibility };
|
package/index.esm.js
CHANGED
|
@@ -2505,7 +2505,6 @@ class FormField {
|
|
|
2505
2505
|
formIndex,
|
|
2506
2506
|
schemaComponent,
|
|
2507
2507
|
config,
|
|
2508
|
-
path,
|
|
2509
2508
|
children,
|
|
2510
2509
|
validateVisibility,
|
|
2511
2510
|
resetValue,
|
|
@@ -2556,6 +2555,7 @@ class FormField {
|
|
|
2556
2555
|
this.fieldValidNotification$ = fieldValidNotification$;
|
|
2557
2556
|
this.mountSubject$ = mountSubject$;
|
|
2558
2557
|
this._props = FormField.filterProps(cloneDeep(schemaComponent.props || {}));
|
|
2558
|
+
this._adapterProps = JSON.stringify(schemaComponent.props || {});
|
|
2559
2559
|
this._metadata = '';
|
|
2560
2560
|
this.errorsString = '';
|
|
2561
2561
|
this.errorsList = [];
|
|
@@ -2615,6 +2615,28 @@ class FormField {
|
|
|
2615
2615
|
});
|
|
2616
2616
|
}
|
|
2617
2617
|
}
|
|
2618
|
+
/**
|
|
2619
|
+
* Retrieves the raw props sent from the adapter.
|
|
2620
|
+
*
|
|
2621
|
+
* @returns {string} - raw props from the adapter
|
|
2622
|
+
*/
|
|
2623
|
+
get adapterProps() {
|
|
2624
|
+
return this._adapterProps;
|
|
2625
|
+
}
|
|
2626
|
+
/**
|
|
2627
|
+
* compares adapter props changes and emits the change if they effectively changed
|
|
2628
|
+
* preventing an emission from the adapter of the same props that can overwrite other prop
|
|
2629
|
+
* changes via templating
|
|
2630
|
+
*/
|
|
2631
|
+
set adapterProps(props) {
|
|
2632
|
+
const currentProps = JSON.stringify(props || {});
|
|
2633
|
+
// it's a very basic comparison to determine if props changed,
|
|
2634
|
+
// will need review if we need complex comparisons
|
|
2635
|
+
if (currentProps !== this.adapterProps) {
|
|
2636
|
+
this.props = FormField.filterProps(props);
|
|
2637
|
+
this._adapterProps = currentProps;
|
|
2638
|
+
}
|
|
2639
|
+
}
|
|
2618
2640
|
/**
|
|
2619
2641
|
* Retrieves the properties associated with the form field.
|
|
2620
2642
|
*
|
|
@@ -4088,7 +4110,9 @@ class FormCore {
|
|
|
4088
4110
|
const values = {};
|
|
4089
4111
|
const metadata = {};
|
|
4090
4112
|
const erroredFields = [];
|
|
4113
|
+
const bindFields = {};
|
|
4091
4114
|
this.fields.forEach((val, key) => {
|
|
4115
|
+
var _a;
|
|
4092
4116
|
if (!(typeof val.value === 'string' && val.value.length === 0) && typeof val.value !== 'undefined' && val.value !== null) {
|
|
4093
4117
|
set(values, val.nameToSubmit || key, val.value);
|
|
4094
4118
|
metadata[key] = val.metadata;
|
|
@@ -4096,11 +4120,18 @@ class FormCore {
|
|
|
4096
4120
|
if (!val.valid) {
|
|
4097
4121
|
erroredFields.push(key);
|
|
4098
4122
|
}
|
|
4123
|
+
if (val.nameToSubmit) {
|
|
4124
|
+
bindFields[key] = {
|
|
4125
|
+
path: (_a = val.nameToSubmit) === null || _a === void 0 ? void 0 : _a.replace('.', '/'),
|
|
4126
|
+
value: val.value
|
|
4127
|
+
};
|
|
4128
|
+
}
|
|
4099
4129
|
});
|
|
4100
4130
|
return {
|
|
4101
4131
|
values,
|
|
4102
4132
|
metadata,
|
|
4103
4133
|
erroredFields,
|
|
4134
|
+
bindFields,
|
|
4104
4135
|
isValid: this.valid
|
|
4105
4136
|
};
|
|
4106
4137
|
}
|
|
@@ -4139,10 +4170,12 @@ class FormCore {
|
|
|
4139
4170
|
formIndex
|
|
4140
4171
|
}) => this.index === formIndex && this.submitChecker()), groupBy(payload => payload.event), mergeMap(group$ => group$.pipe(debounceTime(this.config.defaultStateRefreshTimeMS))), map(({
|
|
4141
4172
|
fieldIndex
|
|
4142
|
-
}) =>
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4173
|
+
}) => {
|
|
4174
|
+
return {
|
|
4175
|
+
field: fieldIndex,
|
|
4176
|
+
data: this.getFormValues()
|
|
4177
|
+
};
|
|
4178
|
+
})).subscribe({
|
|
4146
4179
|
next: callback
|
|
4147
4180
|
});
|
|
4148
4181
|
return sub;
|