@bolttech/form-engine-core 0.0.1-beta.7 → 0.0.1-beta.8
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 +29 -27
- package/package.json +1 -1
- package/src/interfaces/state.d.ts +1 -6
- package/src/managers/field.d.ts +8 -20
- package/src/managers/form.d.ts +4 -4
- package/src/types/form.d.ts +8 -8
package/index.esm.js
CHANGED
|
@@ -2309,7 +2309,6 @@ class FormField {
|
|
|
2309
2309
|
this.masks = schemaComponent.masks;
|
|
2310
2310
|
if (mapper.valueChangeEvent) this.valueChangeEvent = mapper.valueChangeEvent;
|
|
2311
2311
|
if ((_a = mapper.events) === null || _a === void 0 ? void 0 : _a.setValue) this.valuePropName = mapper.events.setValue;
|
|
2312
|
-
if ((_b = mapper.events) === null || _b === void 0 ? void 0 : _b.setErrorMessage) this.errorMessagePropName = mapper.events.setErrorMessage;
|
|
2313
2312
|
this.mapper = mapper;
|
|
2314
2313
|
this.validateVisibility = validateVisibility;
|
|
2315
2314
|
this.resetValue = resetValue;
|
|
@@ -2318,8 +2317,12 @@ class FormField {
|
|
|
2318
2317
|
this.dataSubject$ = dataSubject$;
|
|
2319
2318
|
this._props = schemaComponent.props || {};
|
|
2320
2319
|
this._value = '';
|
|
2321
|
-
this._stateValue =
|
|
2320
|
+
this._stateValue = ((_b = this.mapper.events) === null || _b === void 0 ? void 0 : _b.setValue) ? {
|
|
2321
|
+
[this.mapper.events.setValue]: ''
|
|
2322
|
+
} : {};
|
|
2322
2323
|
this._metadata = '';
|
|
2324
|
+
this.errorsString = '';
|
|
2325
|
+
this.errorsList = [];
|
|
2323
2326
|
this.initialValue = initialValue;
|
|
2324
2327
|
this._visibility = true;
|
|
2325
2328
|
this._api = {
|
|
@@ -2335,7 +2338,6 @@ class FormField {
|
|
|
2335
2338
|
}, {})
|
|
2336
2339
|
};
|
|
2337
2340
|
this._errors = {};
|
|
2338
|
-
this._errorsString = '';
|
|
2339
2341
|
this._valid = false;
|
|
2340
2342
|
this.initializeObservers();
|
|
2341
2343
|
}
|
|
@@ -2343,6 +2345,7 @@ class FormField {
|
|
|
2343
2345
|
* method to initialize all recycled Subjects and initialize Observers on field instance creation or rerender
|
|
2344
2346
|
*/
|
|
2345
2347
|
initializeObservers() {
|
|
2348
|
+
var _a;
|
|
2346
2349
|
if (!this.valueSubject$ || this.valueSubject$.closed) {
|
|
2347
2350
|
this.valueSubject$ = new Subject();
|
|
2348
2351
|
}
|
|
@@ -2365,10 +2368,11 @@ class FormField {
|
|
|
2365
2368
|
this.apiEventQueueSubject$ = new Subject();
|
|
2366
2369
|
}
|
|
2367
2370
|
this.fieldState$ = combineLatest({
|
|
2368
|
-
errors: this.errorSubject$.pipe(startWith([])),
|
|
2369
2371
|
visibility: this.visibilitySubject$.pipe(startWith(this._visibility)),
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
+
props: this.propsSubject$.pipe(startWith(this._props)),
|
|
2373
|
+
errors: this.errorSubject$.pipe(startWith(Object.assign({}, ((_a = this.mapper.events) === null || _a === void 0 ? void 0 : _a.setErrorMessage) && {
|
|
2374
|
+
[this.mapper.events.setErrorMessage]: this.errorsString
|
|
2375
|
+
})))
|
|
2372
2376
|
});
|
|
2373
2377
|
!this.apiEventQueueSubject$.observed && this.apiEventQueueSubject$.pipe(groupBy(({
|
|
2374
2378
|
event
|
|
@@ -2404,7 +2408,7 @@ class FormField {
|
|
|
2404
2408
|
/**
|
|
2405
2409
|
* Retrieves the current state value of the form field.
|
|
2406
2410
|
*
|
|
2407
|
-
* @returns {unknown} - The current state value of the form field.
|
|
2411
|
+
* @returns {Record<string,unknown>} - The current state value of the form field.
|
|
2408
2412
|
*/
|
|
2409
2413
|
get stateValue() {
|
|
2410
2414
|
return this._stateValue;
|
|
@@ -2412,14 +2416,6 @@ class FormField {
|
|
|
2412
2416
|
get metadata() {
|
|
2413
2417
|
return this._metadata;
|
|
2414
2418
|
}
|
|
2415
|
-
/**
|
|
2416
|
-
* Retrieves the concatenated string of errors associated with the form field.
|
|
2417
|
-
*
|
|
2418
|
-
* @returns {string} - The concatenated string of errors.
|
|
2419
|
-
*/
|
|
2420
|
-
get errorsString() {
|
|
2421
|
-
return this._errorsString;
|
|
2422
|
-
}
|
|
2423
2419
|
/**
|
|
2424
2420
|
* Retrieves the current value of the form field.
|
|
2425
2421
|
*
|
|
@@ -2434,6 +2430,7 @@ class FormField {
|
|
|
2434
2430
|
* @param {unknown} value - The new value to be set.
|
|
2435
2431
|
*/
|
|
2436
2432
|
set value(value) {
|
|
2433
|
+
var _a, _b, _c;
|
|
2437
2434
|
/*
|
|
2438
2435
|
too much unstable, if the valueChangeEvent parses the template event
|
|
2439
2436
|
value, might occur unexpected results
|
|
@@ -2453,14 +2450,19 @@ class FormField {
|
|
|
2453
2450
|
if (typeof val === 'undefined' || val === null) return;
|
|
2454
2451
|
if (typeof val === 'object' && '_value' in val && '_metadata' in val) {
|
|
2455
2452
|
this._value = this.formatValue(val['_value']);
|
|
2456
|
-
this._stateValue =
|
|
2453
|
+
this._stateValue = ((_a = this.mapper.events) === null || _a === void 0 ? void 0 : _a.setValue) ? {
|
|
2454
|
+
[this.mapper.events.setValue]: this.maskValue(this.formatValue(val['_value']))
|
|
2455
|
+
} : {};
|
|
2457
2456
|
this._metadata = val._metadata;
|
|
2458
2457
|
} else {
|
|
2459
2458
|
this._value = this.formatValue(val);
|
|
2460
|
-
this._stateValue =
|
|
2459
|
+
this._stateValue = ((_b = this.mapper.events) === null || _b === void 0 ? void 0 : _b.setValue) ? {
|
|
2460
|
+
[(_c = this.mapper.events) === null || _c === void 0 ? void 0 : _c.setValue]: this.maskValue(this.formatValue(val))
|
|
2461
|
+
} : {};
|
|
2462
|
+
this.maskValue(this.formatValue(val));
|
|
2461
2463
|
this._metadata = val;
|
|
2462
2464
|
}
|
|
2463
|
-
this.valueSubject$.next(this.
|
|
2465
|
+
this.stateValue && this.valueSubject$.next(this.stateValue);
|
|
2464
2466
|
this.templateSubject$.next({
|
|
2465
2467
|
key: this.name,
|
|
2466
2468
|
event: 'ON_VALUE'
|
|
@@ -2510,10 +2512,17 @@ class FormField {
|
|
|
2510
2512
|
* @param {TErrorMessages} errors - The new error messages to be set.
|
|
2511
2513
|
*/
|
|
2512
2514
|
set errors(errors) {
|
|
2515
|
+
var _a;
|
|
2513
2516
|
if (typeof errors === 'undefined' || isEqual(errors, this.errors)) return;
|
|
2514
2517
|
this._errors = errors;
|
|
2515
|
-
this.
|
|
2516
|
-
this.
|
|
2518
|
+
this.errorsList = Object.values(this.errors);
|
|
2519
|
+
this.errorsString = this.errorsList.join(', ');
|
|
2520
|
+
/**
|
|
2521
|
+
* if any error receieves a list of errors, set a prop for it, currently only supporting a single string
|
|
2522
|
+
*/
|
|
2523
|
+
((_a = this.mapper.events) === null || _a === void 0 ? void 0 : _a.setErrorMessage) && this.errorSubject$.next({
|
|
2524
|
+
[this.mapper.events.setErrorMessage]: this.errorsString
|
|
2525
|
+
});
|
|
2517
2526
|
this.templateSubject$.next({
|
|
2518
2527
|
key: this.name,
|
|
2519
2528
|
event: 'ON_PROPS'
|
|
@@ -2549,11 +2558,8 @@ class FormField {
|
|
|
2549
2558
|
* Mounts the form field by initializing necessary subjects and combining their streams.
|
|
2550
2559
|
*
|
|
2551
2560
|
* @param {object} mountOpts - Adapter mount options.
|
|
2552
|
-
* @param {string} prop.valuePropName - Adapter value property name.
|
|
2553
|
-
* @param {(event: unknown) => unknown} prop.valueChangeEvent - Adapter change event handler function
|
|
2554
2561
|
* @param {(value: unknown) => unknown} prop.valueSubscription - Adapter value change function
|
|
2555
2562
|
* @param {(payload: Partial<IState>) => unknown} prop.propsSubscription - Adapter prop change function
|
|
2556
|
-
* @param {string} prop.errorMessagePropName - error message property name to set errors onto component
|
|
2557
2563
|
* @returns {void}
|
|
2558
2564
|
*/
|
|
2559
2565
|
mountField({
|
|
@@ -2649,10 +2655,6 @@ class FormField {
|
|
|
2649
2655
|
});
|
|
2650
2656
|
this._valid = valid;
|
|
2651
2657
|
this.errors = errors;
|
|
2652
|
-
// remove later
|
|
2653
|
-
if (this.errorMessagePropName) this.props = Object.assign(Object.assign({}, this.props), {
|
|
2654
|
-
[this.errorMessagePropName]: this.errorsString
|
|
2655
|
-
});
|
|
2656
2658
|
}
|
|
2657
2659
|
/**
|
|
2658
2660
|
* WIP expensive function to get updated field validity on each event
|
package/package.json
CHANGED
|
@@ -1,27 +1,22 @@
|
|
|
1
|
-
import { TApiResponse } from '../types/schema';
|
|
2
1
|
/**
|
|
3
2
|
* @interface IState
|
|
4
3
|
* Represents the state of a form component.
|
|
5
4
|
*
|
|
6
5
|
* @property {string[]} errors - The list of error messages.
|
|
7
6
|
* @property {boolean} visibility - The visibility state of the component.
|
|
8
|
-
* @property {TApiResponse} apiResponse - The API response data.
|
|
9
7
|
* @property {Record<string, unknown>} props - The properties of the component.
|
|
10
8
|
*
|
|
11
9
|
* @example
|
|
12
10
|
* ```typescript
|
|
13
11
|
* const state: IState = {
|
|
14
|
-
* errors: ['This field is required.'],
|
|
15
12
|
* visibility: true,
|
|
16
|
-
* apiResponse: { default: { response: null } },
|
|
17
13
|
* props: { type: 'text', value: 'John' }
|
|
18
14
|
* };
|
|
19
15
|
* ```
|
|
20
16
|
*/
|
|
21
17
|
interface IState {
|
|
22
|
-
errors: string[];
|
|
23
18
|
visibility: boolean;
|
|
24
|
-
apiResponse: TApiResponse;
|
|
25
19
|
props: Record<string, unknown>;
|
|
20
|
+
errors: Record<string, unknown>;
|
|
26
21
|
}
|
|
27
22
|
export { IState };
|
package/src/managers/field.d.ts
CHANGED
|
@@ -21,22 +21,22 @@ declare class FormField {
|
|
|
21
21
|
formatters?: TFormatters;
|
|
22
22
|
masks?: TMasks;
|
|
23
23
|
valuePropName?: string;
|
|
24
|
-
errorMessagePropName?: string;
|
|
25
24
|
initialValue?: unknown;
|
|
26
25
|
config: Required<TSchemaFormConfig>;
|
|
27
26
|
mapper: TMapper<unknown>;
|
|
27
|
+
errorsString: string;
|
|
28
|
+
errorsList: string[];
|
|
28
29
|
private _props;
|
|
29
30
|
private _value;
|
|
30
31
|
private _stateValue;
|
|
31
32
|
private _metadata;
|
|
32
33
|
private _visibility;
|
|
33
34
|
private _errors;
|
|
34
|
-
private _errorsString;
|
|
35
35
|
private _api;
|
|
36
36
|
private _valid;
|
|
37
37
|
propsSubject$: Subject<Record<string, unknown>>;
|
|
38
|
-
errorSubject$: Subject<string
|
|
39
|
-
valueSubject$: Subject<unknown
|
|
38
|
+
errorSubject$: Subject<Record<string, unknown>>;
|
|
39
|
+
valueSubject$: Subject<Record<string, unknown>>;
|
|
40
40
|
visibilitySubject$: Subject<boolean>;
|
|
41
41
|
apiSubject$: Subject<TApiResponse>;
|
|
42
42
|
fieldEventSubject$: Subject<TFieldEvent>;
|
|
@@ -119,16 +119,10 @@ declare class FormField {
|
|
|
119
119
|
/**
|
|
120
120
|
* Retrieves the current state value of the form field.
|
|
121
121
|
*
|
|
122
|
-
* @returns {unknown} - The current state value of the form field.
|
|
122
|
+
* @returns {Record<string,unknown>} - The current state value of the form field.
|
|
123
123
|
*/
|
|
124
|
-
get stateValue(): unknown
|
|
124
|
+
get stateValue(): Record<string, unknown>;
|
|
125
125
|
get metadata(): unknown;
|
|
126
|
-
/**
|
|
127
|
-
* Retrieves the concatenated string of errors associated with the form field.
|
|
128
|
-
*
|
|
129
|
-
* @returns {string} - The concatenated string of errors.
|
|
130
|
-
*/
|
|
131
|
-
get errorsString(): string;
|
|
132
126
|
/**
|
|
133
127
|
* Retrieves the current value of the form field.
|
|
134
128
|
*
|
|
@@ -187,15 +181,12 @@ declare class FormField {
|
|
|
187
181
|
* Mounts the form field by initializing necessary subjects and combining their streams.
|
|
188
182
|
*
|
|
189
183
|
* @param {object} mountOpts - Adapter mount options.
|
|
190
|
-
* @param {string} prop.valuePropName - Adapter value property name.
|
|
191
|
-
* @param {(event: unknown) => unknown} prop.valueChangeEvent - Adapter change event handler function
|
|
192
184
|
* @param {(value: unknown) => unknown} prop.valueSubscription - Adapter value change function
|
|
193
185
|
* @param {(payload: Partial<IState>) => unknown} prop.propsSubscription - Adapter prop change function
|
|
194
|
-
* @param {string} prop.errorMessagePropName - error message property name to set errors onto component
|
|
195
186
|
* @returns {void}
|
|
196
187
|
*/
|
|
197
188
|
mountField({ valueSubscription, propsSubscription, }: {
|
|
198
|
-
valueSubscription: (value: unknown) => void;
|
|
189
|
+
valueSubscription: (value: Record<string, unknown>) => void;
|
|
199
190
|
propsSubscription: (payload: Partial<IState>) => void;
|
|
200
191
|
}): void;
|
|
201
192
|
/**
|
|
@@ -206,10 +197,7 @@ declare class FormField {
|
|
|
206
197
|
* @returns {void}
|
|
207
198
|
*/
|
|
208
199
|
emitValue(prop: {
|
|
209
|
-
value: unknown
|
|
210
|
-
_value: unknown;
|
|
211
|
-
_stateValue: unknown;
|
|
212
|
-
};
|
|
200
|
+
value: unknown;
|
|
213
201
|
event: TEvents;
|
|
214
202
|
}): void;
|
|
215
203
|
/**
|
package/src/managers/form.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ declare class FormCore {
|
|
|
18
18
|
key: string;
|
|
19
19
|
event: TMutationEvents;
|
|
20
20
|
}>;
|
|
21
|
-
submitSubject$: Subject<TFormValues
|
|
21
|
+
submitSubject$: Subject<TFormValues<Record<string, unknown>>>;
|
|
22
22
|
fieldEventSubject$: Subject<TFieldEvent>;
|
|
23
23
|
dataSubject$: Subject<{
|
|
24
24
|
key: string;
|
|
@@ -30,7 +30,7 @@ declare class FormCore {
|
|
|
30
30
|
method?: string;
|
|
31
31
|
config: Required<TSchemaFormConfig>;
|
|
32
32
|
mappers?: TMapper<unknown>[];
|
|
33
|
-
onSubmit?: (data: TFormValues) => void;
|
|
33
|
+
onSubmit?: (data: TFormValues<Record<string, unknown>>) => void;
|
|
34
34
|
/**
|
|
35
35
|
* Creates an instance of FormCore.
|
|
36
36
|
*
|
|
@@ -72,7 +72,7 @@ declare class FormCore {
|
|
|
72
72
|
*/
|
|
73
73
|
subscribeData(callback: (payload: {
|
|
74
74
|
field: string;
|
|
75
|
-
data: TFormValues
|
|
75
|
+
data: TFormValues<Record<string, unknown>>;
|
|
76
76
|
}) => void): void;
|
|
77
77
|
/**
|
|
78
78
|
* Gets the value of a property from a field.
|
|
@@ -216,7 +216,7 @@ declare class FormCore {
|
|
|
216
216
|
*
|
|
217
217
|
* @returns {TFormValues} The current form values.
|
|
218
218
|
*/
|
|
219
|
-
getFormValues(): TFormValues
|
|
219
|
+
getFormValues(): TFormValues<Record<string, unknown>>;
|
|
220
220
|
subscribeFieldEvent({ callback, }: {
|
|
221
221
|
callback: (payload: TFieldEvent) => void;
|
|
222
222
|
}): Subscription;
|
package/src/types/form.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { IFormSchema } from '../interfaces/schema';
|
|
2
2
|
import { TMapper } from './mapper';
|
|
3
3
|
/**
|
|
4
|
-
* @type TFormValues
|
|
5
|
-
* Represents the values and state of a form.
|
|
4
|
+
* @type TFormValues<T>
|
|
5
|
+
* 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.
|
|
6
6
|
*
|
|
7
|
-
* @property {
|
|
7
|
+
* @property {Generic Type} values - The current values of the form fields.
|
|
8
8
|
* @property {string[]} erroredFields - A list of field names that have errors.
|
|
9
9
|
* @property {boolean} isValid - Indicates whether the form is valid.
|
|
10
10
|
*
|
|
@@ -17,8 +17,8 @@ import { TMapper } from './mapper';
|
|
|
17
17
|
* };
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
|
-
type TFormValues = {
|
|
21
|
-
values:
|
|
20
|
+
type TFormValues<T> = {
|
|
21
|
+
values: T;
|
|
22
22
|
erroredFields: string[];
|
|
23
23
|
isValid: boolean;
|
|
24
24
|
};
|
|
@@ -41,10 +41,10 @@ type TFormValues = {
|
|
|
41
41
|
*/
|
|
42
42
|
type TFormEntry = Omit<IFormSchema, 'components'> & {
|
|
43
43
|
schema?: IFormSchema;
|
|
44
|
-
onSubmit?: (data: TFormValues) => void;
|
|
45
|
-
onData?: (payload: {
|
|
44
|
+
onSubmit?: <T>(data: TFormValues<T>) => void;
|
|
45
|
+
onData?: <T>(payload: {
|
|
46
46
|
field: string;
|
|
47
|
-
data: TFormValues
|
|
47
|
+
data: TFormValues<T>;
|
|
48
48
|
}) => void;
|
|
49
49
|
mappers?: TMapper<unknown>[];
|
|
50
50
|
};
|