@bolttech/form-engine-core 0.0.1-beta.8 → 0.0.2-beta.1
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 +40 -36
- package/index.esm.js +591 -278
- package/package.json +2 -2
- package/src/constants/constants.d.ts +6 -1
- package/src/helpers/SafeSubject.d.ts +11 -0
- package/src/helpers/helpers.d.ts +3 -1
- package/src/helpers/validation.d.ts +27 -0
- package/src/interfaces/schema.d.ts +30 -8
- package/src/managers/field.d.ts +18 -23
- package/src/managers/form.d.ts +50 -31
- package/src/managers/formGroup.d.ts +10 -2
- package/src/types/event.d.ts +2 -2
- package/src/types/form.d.ts +0 -5
- package/src/types/schema.d.ts +88 -40
- package/src/types/template.d.ts +19 -1
- package/src/types/utility.d.ts +2 -0
- package/src/validations/date.d.ts +1 -0
- package/src/validations/handler.d.ts +2 -2
- package/src/validations/multiple.d.ts +2 -2
- package/src/validations/namedRule.d.ts +22 -0
- package/src/validations/number.d.ts +30 -0
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bolttech/form-engine-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2-beta.01",
|
|
4
4
|
"module": "./index.esm.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.esm.js",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@gaignoux/currency": "1.1.0",
|
|
9
|
-
"credit-card-type": "10.0.
|
|
9
|
+
"credit-card-type": "10.0.1",
|
|
10
10
|
"lodash": "4.17.21",
|
|
11
11
|
"rxjs": "7.8.1"
|
|
12
12
|
},
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
declare const DEFAULT_API_DEBOUNCE_TIME = 1000;
|
|
2
2
|
declare const DEFAULT_STATE_REFRESH_TIME = 100;
|
|
3
|
-
|
|
3
|
+
declare const TEMPLATE_REGEX_STRING_CONCATENATION_DETECTOR: RegExp;
|
|
4
|
+
declare const TEMPLATE_REGEX_DELIMITATOR: RegExp;
|
|
5
|
+
declare const TEMPLATE_REGEX_OPERATOR_SPLITTER: RegExp;
|
|
6
|
+
declare const TEMPLATE_REGEX_OPERATOR_MATCHER: RegExp;
|
|
7
|
+
declare const TEMPLATE_AVALIABLE_SCOPES: readonly ["fields", "iVars"];
|
|
8
|
+
export { DEFAULT_API_DEBOUNCE_TIME, DEFAULT_STATE_REFRESH_TIME, TEMPLATE_REGEX_STRING_CONCATENATION_DETECTOR, TEMPLATE_REGEX_DELIMITATOR, TEMPLATE_REGEX_OPERATOR_SPLITTER, TEMPLATE_REGEX_OPERATOR_MATCHER, TEMPLATE_AVALIABLE_SCOPES, };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Subject } from 'rxjs';
|
|
2
|
+
/**
|
|
3
|
+
* Custom RXJS Subject to gracefully handle errors on unsubscribed Subjects
|
|
4
|
+
* that were unmounted due to adapter external handling such as visibility
|
|
5
|
+
*/
|
|
6
|
+
declare class SafeSubject<T> extends Subject<T> {
|
|
7
|
+
private isMounted;
|
|
8
|
+
constructor(isMounted: () => boolean);
|
|
9
|
+
next(value: T): void;
|
|
10
|
+
}
|
|
11
|
+
export { SafeSubject };
|
package/src/helpers/helpers.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
import { TEMPLATE_AVALIABLE_SCOPES } from '../constants/constants';
|
|
2
3
|
import { TSubscribedTemplates } from '../types/template';
|
|
3
4
|
import { OutgoingHttpHeaders } from 'http2';
|
|
4
5
|
/**
|
|
@@ -32,6 +33,7 @@ declare function makeRequest(method: string, url: string, headers?: OutgoingHttp
|
|
|
32
33
|
* ```
|
|
33
34
|
*/
|
|
34
35
|
declare function extractFieldKeys(expression: string): {
|
|
36
|
+
originScopeKeys: (typeof TEMPLATE_AVALIABLE_SCOPES)[number][];
|
|
35
37
|
originFieldKeys: string[];
|
|
36
38
|
originPropertyKeys: string[];
|
|
37
39
|
};
|
|
@@ -60,5 +62,5 @@ declare function extractFieldKeys(expression: string): {
|
|
|
60
62
|
* // expressions will contain an array of objects with origin expressions, field keys, and destination paths.
|
|
61
63
|
* ```
|
|
62
64
|
*/
|
|
63
|
-
declare function traverseObject(
|
|
65
|
+
declare function traverseObject(element: any, path?: string): TSubscribedTemplates[];
|
|
64
66
|
export { makeRequest, traverseObject, extractFieldKeys };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { TSchemaValidation, TValidationMethods } from '../types/schema';
|
|
2
|
+
import { TValidationHandler } from '../types/utility';
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
* Handles the validation of a given value based on specified validation methods and rules.
|
|
6
|
+
*
|
|
7
|
+
* @param {string | number | boolean | unknown} value - The value to be validated.
|
|
8
|
+
* @param {TSchemaValidation} validations - The schema validations to be applied.
|
|
9
|
+
* @param {TValidationHandler} methods - The validation handler methods.
|
|
10
|
+
* @param {keyof TValidationMethods} key - The specific key of the validation method to be used.
|
|
11
|
+
* @returns {boolean} - Returns true if the value passes the validation, otherwise false.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const value = 'example@example.com';
|
|
15
|
+
* const validations = {
|
|
16
|
+
* required: true,
|
|
17
|
+
* customName: { email: true }
|
|
18
|
+
* };
|
|
19
|
+
* const methods = {
|
|
20
|
+
* email: (value) => /\S+@\S+\.\S+/.test(value)
|
|
21
|
+
* };
|
|
22
|
+
* const key = 'required';
|
|
23
|
+
*
|
|
24
|
+
* const isValid = handleValidation(value, validations, methods, key);
|
|
25
|
+
* console.log(isValid); // Output: true
|
|
26
|
+
*/
|
|
27
|
+
export default function handleValidation(value: string | number | boolean | unknown, validations: TSchemaValidation, methods: TValidationHandler, key: keyof TValidationMethods): boolean;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TMapper } from '../types/mapper';
|
|
2
|
+
import { TApiEvent, TFormatters, TMasks, TProps, TResetValueMethods, TSchemaFormConfig, TValidations, TVisibility } from '../types/schema';
|
|
2
3
|
/**
|
|
3
4
|
* @interface IComponentSchema
|
|
4
5
|
* Represents the schema for a component within a form.
|
|
@@ -6,10 +7,10 @@ import { TApiEvent, TErrorMessages, TEvent, TFormatters, TMasks, TProps, TResetV
|
|
|
6
7
|
* @property {string} component - The type of component (e.g., 'input', 'button').
|
|
7
8
|
* @property {TProps} props - The properties of the component.
|
|
8
9
|
* @property {string} name - The name of the component.
|
|
9
|
-
* @property {
|
|
10
|
+
* @property {string} nameToSubmit - The name of the field when submit values (optional).
|
|
11
|
+
* @property {TValidations} [validations] - The validation methods for the component.
|
|
10
12
|
* @property {TVisibility[]} [visibilityConditions] - The visibility conditions for the component.
|
|
11
13
|
* @property {TResetValueMethods[]} [resetValues] - The reset value methods for the component.
|
|
12
|
-
* @property {TErrorMessages} [errorMessages] - The error messages for the component.
|
|
13
14
|
* @property {TApiEvent} [api] - The API configuration for the component.
|
|
14
15
|
* @property {TFormatters} [formatters] - The formatters for the component.
|
|
15
16
|
* @property {TMasks} [masks] - The masks for the component.
|
|
@@ -21,10 +22,26 @@ import { TApiEvent, TErrorMessages, TEvent, TFormatters, TMasks, TProps, TResetV
|
|
|
21
22
|
* component: 'input',
|
|
22
23
|
* props: { type: 'text', placeholder: 'Enter your name' },
|
|
23
24
|
* name: 'name',
|
|
24
|
-
*
|
|
25
|
+
* nameToSubmit: 'applicant.firstName',
|
|
26
|
+
* validations: {
|
|
27
|
+
* methods: {
|
|
28
|
+
* required: true,
|
|
29
|
+
* regex: '^([0-9]+)*$',
|
|
30
|
+
* max: 5,
|
|
31
|
+
* },
|
|
32
|
+
* eventMessages: {
|
|
33
|
+
* ON_FIELD_MOUNT: ['required'],
|
|
34
|
+
* ON_FIELD_CHANGE: ['regex', 'required'],
|
|
35
|
+
* ON_FIELD_BLUR: ['max', 'required'],
|
|
36
|
+
* },
|
|
37
|
+
* messages: {
|
|
38
|
+
* default: 'This field is required',
|
|
39
|
+
* regex: 'Only numbers are available.',
|
|
40
|
+
* max: 'Max of 5',
|
|
41
|
+
* },
|
|
42
|
+
* },
|
|
25
43
|
* visibilityConditions: [{ conditions: { field: 'age', value: 18 } }],
|
|
26
44
|
* resetValues: [{ field: 'age', resetTo: '' }],
|
|
27
|
-
* errorMessages: { required: 'This field is required.' },
|
|
28
45
|
* api: { defaultConfig: { config: { method: 'POST', url: 'https://api.example.com/submit' }, events: [{ eventName: 'ON_FORM_SUBMIT' }] } },
|
|
29
46
|
* formatters: { capitalize: true },
|
|
30
47
|
* masks: { currency: { align: 'left', decimal: '.', precision: 2, prefix: '$', thousands: ',' } },
|
|
@@ -36,15 +53,20 @@ interface IComponentSchema {
|
|
|
36
53
|
component: string;
|
|
37
54
|
props?: TProps;
|
|
38
55
|
name: string;
|
|
39
|
-
|
|
56
|
+
nameToSubmit?: string;
|
|
57
|
+
validations?: TValidations;
|
|
40
58
|
api?: TApiEvent;
|
|
41
59
|
visibilityConditions?: TVisibility[];
|
|
42
60
|
resetValues?: TResetValueMethods[];
|
|
43
|
-
errorMessages?: TErrorMessages;
|
|
44
61
|
formatters?: TFormatters;
|
|
45
62
|
masks?: TMasks;
|
|
46
63
|
children?: IComponentSchema[];
|
|
47
64
|
}
|
|
65
|
+
interface IComponentSchemaAsFormField<T> extends IComponentSchema {
|
|
66
|
+
mapper?: TMapper<T>;
|
|
67
|
+
order?: number;
|
|
68
|
+
children?: IComponentSchemaAsFormField<T>[];
|
|
69
|
+
}
|
|
48
70
|
/**
|
|
49
71
|
* @interface IFormSchema
|
|
50
72
|
* Represents the schema for a form.
|
|
@@ -80,4 +102,4 @@ interface IFormSchema {
|
|
|
80
102
|
iVars?: Record<string, unknown>;
|
|
81
103
|
components?: IComponentSchema[];
|
|
82
104
|
}
|
|
83
|
-
export { IFormSchema, IComponentSchema };
|
|
105
|
+
export { IFormSchema, IComponentSchema, IComponentSchemaAsFormField };
|
package/src/managers/field.d.ts
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import { Observable, Subject, Subscription } from 'rxjs';
|
|
2
|
-
import { TApiConfig, TApiEvent, TApiResponse, TErrorMessages,
|
|
3
|
-
import { IComponentSchema } from '../interfaces/schema';
|
|
2
|
+
import { TApiConfig, TApiEvent, TApiResponse, TErrorMessages, TFormatters, TMasks, TResetValueMethods, TSchemaFormConfig, TValidations, TVisibility } from '../types/schema';
|
|
3
|
+
import { IComponentSchema, IComponentSchemaAsFormField } from '../interfaces/schema';
|
|
4
4
|
import { IState } from '../interfaces/state';
|
|
5
|
-
import { TEvents, TFieldEvent,
|
|
5
|
+
import { TEvents, TFieldEvent, TValueChangeEvent } from '../types/event';
|
|
6
6
|
import { TMapper } from '../types/mapper';
|
|
7
|
+
import { SafeSubject } from '../helpers/SafeSubject';
|
|
8
|
+
import { TTemplateEvent } from '../types/template';
|
|
7
9
|
/**
|
|
8
10
|
* Represents a form field with observables for managing form state, validations, and API requests.
|
|
9
11
|
*/
|
|
10
12
|
declare class FormField {
|
|
11
13
|
name: string;
|
|
14
|
+
nameToSubmit?: string;
|
|
12
15
|
component: string;
|
|
13
16
|
path?: string;
|
|
14
17
|
children?: string[];
|
|
15
|
-
originalSchema:
|
|
16
|
-
validations?:
|
|
18
|
+
originalSchema: IComponentSchemaAsFormField<unknown>;
|
|
19
|
+
validations?: TValidations;
|
|
17
20
|
visibilityConditions?: TVisibility[];
|
|
18
21
|
resetValues?: TResetValueMethods[];
|
|
19
22
|
errorMessages?: TErrorMessages;
|
|
@@ -34,21 +37,20 @@ declare class FormField {
|
|
|
34
37
|
private _errors;
|
|
35
38
|
private _api;
|
|
36
39
|
private _valid;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
private _mounted;
|
|
41
|
+
propsSubject$: SafeSubject<Record<string, unknown>>;
|
|
42
|
+
errorSubject$: SafeSubject<Record<string, unknown>>;
|
|
43
|
+
valueSubject$: SafeSubject<Record<string, unknown>>;
|
|
44
|
+
valueSubscription$: Subscription;
|
|
45
|
+
visibilitySubject$: SafeSubject<boolean>;
|
|
46
|
+
apiSubject$: SafeSubject<TApiResponse>;
|
|
42
47
|
fieldEventSubject$: Subject<TFieldEvent>;
|
|
43
|
-
apiEventQueueSubject$:
|
|
48
|
+
apiEventQueueSubject$: SafeSubject<{
|
|
44
49
|
event: TEvents;
|
|
45
50
|
}>;
|
|
46
51
|
fieldState$: Observable<IState>;
|
|
47
52
|
fieldStateSubscription$: Subscription;
|
|
48
|
-
templateSubject$: Subject<
|
|
49
|
-
key: string;
|
|
50
|
-
event: TMutationEvents;
|
|
51
|
-
}>;
|
|
53
|
+
templateSubject$: Subject<TTemplateEvent>;
|
|
52
54
|
dataSubject$: Subject<{
|
|
53
55
|
key: string;
|
|
54
56
|
event: TEvents;
|
|
@@ -89,10 +91,7 @@ declare class FormField {
|
|
|
89
91
|
key: string;
|
|
90
92
|
}) => void;
|
|
91
93
|
initialValue?: unknown;
|
|
92
|
-
templateSubject$: Subject<
|
|
93
|
-
key: string;
|
|
94
|
-
event: TMutationEvents;
|
|
95
|
-
}>;
|
|
94
|
+
templateSubject$: Subject<TTemplateEvent>;
|
|
96
95
|
fieldEventSubject$: Subject<TFieldEvent>;
|
|
97
96
|
dataSubject$: Subject<{
|
|
98
97
|
key: string;
|
|
@@ -218,10 +217,6 @@ declare class FormField {
|
|
|
218
217
|
setFieldValidity({ event }: {
|
|
219
218
|
event: TEvents;
|
|
220
219
|
}): void;
|
|
221
|
-
/**
|
|
222
|
-
* WIP expensive function to get updated field validity on each event
|
|
223
|
-
*/
|
|
224
|
-
updateValidityFlag(): void;
|
|
225
220
|
/**
|
|
226
221
|
* Formats the field value using the specified formatters, if available.
|
|
227
222
|
*
|
package/src/managers/form.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { IFormField } from './field';
|
|
2
2
|
import { Subject, Subscription } from 'rxjs';
|
|
3
|
-
import { IComponentSchema, IFormSchema } from '../interfaces/schema';
|
|
3
|
+
import { IComponentSchema, IComponentSchemaAsFormField, IFormSchema } from '../interfaces/schema';
|
|
4
4
|
import { TSchemaFormConfig } from '../types/schema';
|
|
5
|
-
import { TSubscribedTemplates } from '../types/template';
|
|
5
|
+
import { TSubscribedTemplates, TTemplateEvent } from '../types/template';
|
|
6
6
|
import { TEvents, TFieldEvent, TMutationEvents } from '../types/event';
|
|
7
7
|
import { TFormEntry, TFormValues } from '../types/form';
|
|
8
8
|
import { TMapper } from '../types/mapper';
|
|
9
|
+
import { TEMPLATE_AVALIABLE_SCOPES } from '../constants/constants';
|
|
9
10
|
/**
|
|
10
11
|
* Represents the core logic for managing a form, including field management, validation, and submission.
|
|
11
12
|
*/
|
|
@@ -14,23 +15,20 @@ declare class FormCore {
|
|
|
14
15
|
fields: Map<string, IFormField>;
|
|
15
16
|
initialValues?: Record<string, unknown>;
|
|
16
17
|
private _iVars;
|
|
17
|
-
templateSubject$: Subject<
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
submitSubject$: Subject<TFormValues<Record<string, unknown>>>;
|
|
18
|
+
templateSubject$: Subject<TTemplateEvent>;
|
|
19
|
+
templateSubscription$: Subscription;
|
|
20
|
+
submitSubject$: Subject<TFormValues<any>>;
|
|
21
|
+
mountSubject$: Subject<TFormValues<any>>;
|
|
22
22
|
fieldEventSubject$: Subject<TFieldEvent>;
|
|
23
23
|
dataSubject$: Subject<{
|
|
24
24
|
key: string;
|
|
25
25
|
event: TEvents;
|
|
26
26
|
}>;
|
|
27
|
-
dataCallbackSubscription$: Subscription;
|
|
28
27
|
subscribedTemplates: TSubscribedTemplates[];
|
|
29
28
|
action?: string;
|
|
30
29
|
method?: string;
|
|
31
30
|
config: Required<TSchemaFormConfig>;
|
|
32
|
-
mappers
|
|
33
|
-
onSubmit?: (data: TFormValues<Record<string, unknown>>) => void;
|
|
31
|
+
mappers: Map<string, TMapper<unknown>>;
|
|
34
32
|
/**
|
|
35
33
|
* Creates an instance of FormCore.
|
|
36
34
|
*
|
|
@@ -40,7 +38,6 @@ declare class FormCore {
|
|
|
40
38
|
* @param {string} [entry.action] - The action attribute of the form.
|
|
41
39
|
* @param {string} [entry.method] - The method attribute of the form.
|
|
42
40
|
* @param {IFormSchema.iVars} [entry.iVars] - The internal variables of the form.
|
|
43
|
-
* @param {(data: TFormValues) => void} [entry.onSubmit] - A callback function to handle form submission.
|
|
44
41
|
* @param {((payload: {field: string;data: TFormValues;}) => void) | undefined} [entry.onData] - A callback function to handle data emission.
|
|
45
42
|
*/
|
|
46
43
|
constructor(entry: TFormEntry & Omit<IFormSchema, 'components'>);
|
|
@@ -66,14 +63,6 @@ declare class FormCore {
|
|
|
66
63
|
* Subscribes to templates for dynamic updates.
|
|
67
64
|
*/
|
|
68
65
|
subscribeTemplates(): void;
|
|
69
|
-
/**
|
|
70
|
-
*
|
|
71
|
-
* @param {(payload: { field: string; data: TFormValues }) => void} callback callback function to call on data
|
|
72
|
-
*/
|
|
73
|
-
subscribeData(callback: (payload: {
|
|
74
|
-
field: string;
|
|
75
|
-
data: TFormValues<Record<string, unknown>>;
|
|
76
|
-
}) => void): void;
|
|
77
66
|
/**
|
|
78
67
|
* Gets the value of a property from a field.
|
|
79
68
|
*
|
|
@@ -83,7 +72,8 @@ declare class FormCore {
|
|
|
83
72
|
* @param {string[]} options.path - The path to the property if it's nested.
|
|
84
73
|
* @returns {unknown | undefined} The value of the property, or undefined if the field doesn't exist.
|
|
85
74
|
*/
|
|
86
|
-
getValue({ key, property, path, }: {
|
|
75
|
+
getValue({ scope, key, property, path, }: {
|
|
76
|
+
scope: (typeof TEMPLATE_AVALIABLE_SCOPES)[number];
|
|
87
77
|
key: string;
|
|
88
78
|
property: string;
|
|
89
79
|
path: string[];
|
|
@@ -103,7 +93,7 @@ declare class FormCore {
|
|
|
103
93
|
key: string;
|
|
104
94
|
property: string;
|
|
105
95
|
path: string[];
|
|
106
|
-
originKey
|
|
96
|
+
originKey?: string;
|
|
107
97
|
value: unknown;
|
|
108
98
|
event: TMutationEvents;
|
|
109
99
|
}): void;
|
|
@@ -113,7 +103,7 @@ declare class FormCore {
|
|
|
113
103
|
* @param {string} expression - The expression containing parameters.
|
|
114
104
|
* @returns {string[]} An array of extracted parameters.
|
|
115
105
|
*/
|
|
116
|
-
extractParams(expression: string):
|
|
106
|
+
extractParams(expression: string): unknown[];
|
|
117
107
|
/**
|
|
118
108
|
* Replaces expressions marked by ${...} in the expression string with the provided values.
|
|
119
109
|
*
|
|
@@ -121,7 +111,7 @@ declare class FormCore {
|
|
|
121
111
|
* @param {string[]} values - The values to be inserted into the marked expressions.
|
|
122
112
|
* @returns {string} The expression string with the replacements made.
|
|
123
113
|
*/
|
|
124
|
-
replaceExpression(expression: string, values:
|
|
114
|
+
replaceExpression(expression: string, values: unknown[]): string;
|
|
125
115
|
/**
|
|
126
116
|
* Checks if an expression string contains string concatenation within a marked expression.
|
|
127
117
|
*
|
|
@@ -136,10 +126,7 @@ declare class FormCore {
|
|
|
136
126
|
* @param {string} options.key - The key of the field triggering the update.
|
|
137
127
|
* @param {TMutationEvents} options.event - Internal event descriptor to handle templating.
|
|
138
128
|
*/
|
|
139
|
-
refreshTemplates({ key, event }:
|
|
140
|
-
key: string;
|
|
141
|
-
event: TMutationEvents;
|
|
142
|
-
}): void;
|
|
129
|
+
refreshTemplates({ key, event }: TTemplateEvent): void;
|
|
143
130
|
/**
|
|
144
131
|
* Validates and collects the names of form fields in the provided schema structure.
|
|
145
132
|
*
|
|
@@ -150,6 +137,15 @@ declare class FormCore {
|
|
|
150
137
|
* @private
|
|
151
138
|
*/
|
|
152
139
|
private static checkIndexes;
|
|
140
|
+
/**
|
|
141
|
+
* @internal
|
|
142
|
+
* Update field visibility accordingly.
|
|
143
|
+
*
|
|
144
|
+
* @param {string} field - Field name to be updated.
|
|
145
|
+
* @param {boolean} hasError - Condition to be used as visibility.
|
|
146
|
+
* @param {boolean|undefined} showOnlyIfTrue - Flag to be considered when update field visibility. If it's true, then considered error, if it's false, always considered the opposite.
|
|
147
|
+
*/
|
|
148
|
+
private setFieldVisibility;
|
|
153
149
|
/**
|
|
154
150
|
* Validates visibility conditions for a given event and updates field visibility accordingly.
|
|
155
151
|
*
|
|
@@ -161,6 +157,14 @@ declare class FormCore {
|
|
|
161
157
|
event: TEvents;
|
|
162
158
|
key: string;
|
|
163
159
|
}): void;
|
|
160
|
+
/**
|
|
161
|
+
* @internal
|
|
162
|
+
* Update field value and emit change and cleared event.
|
|
163
|
+
*
|
|
164
|
+
* @param {string} key - Field name to be updated.
|
|
165
|
+
* @param {unknown} value - Value to be inserted into field.
|
|
166
|
+
*/
|
|
167
|
+
private setResetFieldValue;
|
|
164
168
|
/**
|
|
165
169
|
* Resets field values based on reset conditions defined in the schema.
|
|
166
170
|
*
|
|
@@ -176,6 +180,7 @@ declare class FormCore {
|
|
|
176
180
|
* Adds a field onto the form instance regardless there is a schema or not
|
|
177
181
|
*
|
|
178
182
|
* @param fieldSchema
|
|
183
|
+
* @param mapperElement
|
|
179
184
|
*/
|
|
180
185
|
addField({ fieldSchema, mapperElement, }: {
|
|
181
186
|
fieldSchema: IComponentSchema;
|
|
@@ -190,13 +195,13 @@ declare class FormCore {
|
|
|
190
195
|
* @param {IComponentSchema[]} [struct] - The schema structure to serialize.
|
|
191
196
|
* @param {string} [path] - The path of the parent component.
|
|
192
197
|
*/
|
|
193
|
-
serializeStructure(struct?:
|
|
198
|
+
serializeStructure(struct?: IComponentSchemaAsFormField<unknown>[], path?: string): void;
|
|
194
199
|
/**
|
|
195
200
|
* Refreshes form fields based on changes in the schema structure.
|
|
196
201
|
*
|
|
197
202
|
* @param {IComponentSchema[]} struct - The updated schema structure.
|
|
198
203
|
*/
|
|
199
|
-
refreshFields(struct:
|
|
204
|
+
refreshFields(struct: IComponentSchemaAsFormField<unknown>[]): void;
|
|
200
205
|
/**
|
|
201
206
|
* Gets a form field by its key.
|
|
202
207
|
*
|
|
@@ -216,14 +221,28 @@ declare class FormCore {
|
|
|
216
221
|
*
|
|
217
222
|
* @returns {TFormValues} The current form values.
|
|
218
223
|
*/
|
|
219
|
-
getFormValues(): TFormValues<
|
|
224
|
+
getFormValues<T>(): TFormValues<T>;
|
|
220
225
|
subscribeFieldEvent({ callback, }: {
|
|
221
226
|
callback: (payload: TFieldEvent) => void;
|
|
222
227
|
}): Subscription;
|
|
228
|
+
subscribeOnMount<T>(callback: (payload: TFormValues<T>) => void): Subscription;
|
|
229
|
+
/**
|
|
230
|
+
*
|
|
231
|
+
* @param {(payload: { field: string; data: TFormValues }) => void} callback callback function to call on data
|
|
232
|
+
*/
|
|
233
|
+
subscribeData<T>(callback: (payload: {
|
|
234
|
+
field: string;
|
|
235
|
+
data: TFormValues<T>;
|
|
236
|
+
}) => void): Subscription;
|
|
237
|
+
subscribeOnSubmit<T>(callback: (payload: TFormValues<T>) => void): Subscription;
|
|
238
|
+
/**
|
|
239
|
+
* Submits the form by triggering form field events and invoking the onSubmit callback.
|
|
240
|
+
*/
|
|
241
|
+
mounted<T>(): void;
|
|
223
242
|
/**
|
|
224
243
|
* Submits the form by triggering form field events and invoking the onSubmit callback.
|
|
225
244
|
*/
|
|
226
|
-
submit(): void;
|
|
245
|
+
submit<T>(): void;
|
|
227
246
|
destroy(): void;
|
|
228
247
|
}
|
|
229
248
|
type TFormCore = FormCore;
|
|
@@ -56,7 +56,7 @@ declare class FormGroup {
|
|
|
56
56
|
* @param {string} options.formIndex
|
|
57
57
|
* @param {string} options.fieldIndex
|
|
58
58
|
*/
|
|
59
|
-
removeField({ formIndex, fieldIndex }: {
|
|
59
|
+
removeField({ formIndex, fieldIndex, }: {
|
|
60
60
|
formIndex: string;
|
|
61
61
|
fieldIndex: string;
|
|
62
62
|
}): void;
|
|
@@ -79,7 +79,15 @@ declare class FormGroup {
|
|
|
79
79
|
* @param {string[]} indexes form indexes to be submitted
|
|
80
80
|
* @returns
|
|
81
81
|
*/
|
|
82
|
-
submitMultipleFormsByIndex(indexes: string[]):
|
|
82
|
+
submitMultipleFormsByIndex<T>(indexes: string[], callback?: (payload: TFormValues<T>) => void): void;
|
|
83
|
+
onDataSubscription<T>({ ids, callback, }: {
|
|
84
|
+
ids: string[];
|
|
85
|
+
callback: (payload: Record<string, {
|
|
86
|
+
formId: string;
|
|
87
|
+
formField: string;
|
|
88
|
+
values?: TFormValues<T>;
|
|
89
|
+
}>) => void;
|
|
90
|
+
}): import("rxjs").Subscription;
|
|
83
91
|
}
|
|
84
92
|
type TFormGroup = FormGroup;
|
|
85
93
|
export { TFormGroup, FormGroup };
|
package/src/types/event.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { IFormField } from '../managers';
|
|
|
8
8
|
* const event: TEvents = 'ON_FIELD_CHANGE';
|
|
9
9
|
* ```
|
|
10
10
|
*/
|
|
11
|
-
type TEvents = 'ON_FIELD_MOUNT' | 'ON_FIELD_CHANGE' | 'ON_FIELD_BLUR' | 'ON_FIELD_FOCUS' | 'ON_FIELD_CLICK' | 'ON_FIELD_KEYUP' | 'ON_FIELD_KEYDOWN' | 'ON_FORM_SUBMIT' | 'ON_API_FIELD_RESPONSE';
|
|
11
|
+
type TEvents = 'ON_FIELD_MOUNT' | 'ON_FIELD_CHANGE' | 'ON_FIELD_BLUR' | 'ON_FIELD_FOCUS' | 'ON_FIELD_CLICK' | 'ON_FIELD_KEYUP' | 'ON_FIELD_KEYDOWN' | 'ON_FIELD_CLEARED' | 'ON_FORM_SUBMIT' | 'ON_FORM_MOUNT' | 'ON_API_FIELD_RESPONSE';
|
|
12
12
|
/**
|
|
13
13
|
* @type TMutationEvents
|
|
14
14
|
* Represents the different types of events that can occur internally that triggers templating.
|
|
@@ -46,4 +46,4 @@ type TFieldEvent = {
|
|
|
46
46
|
fieldName: string;
|
|
47
47
|
fieldInstance?: IFormField;
|
|
48
48
|
};
|
|
49
|
-
export { TEvents, TMutationEvents, TMutationEnum, TValueChangeEvent, TFieldEvent };
|
|
49
|
+
export { TEvents, TMutationEvents, TMutationEnum, TValueChangeEvent, TFieldEvent, };
|
package/src/types/form.d.ts
CHANGED
|
@@ -41,11 +41,6 @@ type TFormValues<T> = {
|
|
|
41
41
|
*/
|
|
42
42
|
type TFormEntry = Omit<IFormSchema, 'components'> & {
|
|
43
43
|
schema?: IFormSchema;
|
|
44
|
-
onSubmit?: <T>(data: TFormValues<T>) => void;
|
|
45
|
-
onData?: <T>(payload: {
|
|
46
|
-
field: string;
|
|
47
|
-
data: TFormValues<T>;
|
|
48
|
-
}) => void;
|
|
49
44
|
mappers?: TMapper<unknown>[];
|
|
50
45
|
};
|
|
51
46
|
export { TFormValues, TFormEntry };
|