@bolttech/form-engine-core 0.0.1-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/index.esm.d.ts +1 -0
- package/index.esm.js +3518 -0
- package/package.json +14 -0
- package/src/formatters/creditCard.d.ts +23 -0
- package/src/formatters/custom.d.ts +29 -0
- package/src/formatters/handler.d.ts +2 -0
- package/src/formatters/regex.d.ts +47 -0
- package/src/formatters/splitter.d.ts +17 -0
- package/src/formatters/string.d.ts +88 -0
- package/src/helpers/creditCard.d.ts +95 -0
- package/src/helpers/helpers.d.ts +64 -0
- package/src/index.d.ts +10 -0
- package/src/interfaces/schema.d.ts +82 -0
- package/src/interfaces/state.d.ts +27 -0
- package/src/managers/field.d.ts +294 -0
- package/src/managers/form.d.ts +224 -0
- package/src/managers/formGroup.d.ts +64 -0
- package/src/masks/creditCard.d.ts +60 -0
- package/src/masks/generic.d.ts +39 -0
- package/src/masks/handler.d.ts +2 -0
- package/src/masks/string.d.ts +97 -0
- package/src/types/event.d.ts +43 -0
- package/src/types/form.d.ts +51 -0
- package/src/types/mapper.d.ts +94 -0
- package/src/types/schema.d.ts +742 -0
- package/src/types/template.d.ts +32 -0
- package/src/types/utility.d.ts +4 -0
- package/src/validations/creditCard.d.ts +52 -0
- package/src/validations/custom.d.ts +25 -0
- package/src/validations/date.d.ts +78 -0
- package/src/validations/document.d.ts +25 -0
- package/src/validations/handler.d.ts +2 -0
- package/src/validations/length.d.ts +39 -0
- package/src/validations/list.d.ts +32 -0
- package/src/validations/logical.d.ts +75 -0
- package/src/validations/multiple.d.ts +31 -0
- package/src/validations/number.d.ts +115 -0
- package/src/validations/object.d.ts +44 -0
- package/src/validations/regex.d.ts +217 -0
- package/src/validations/string.d.ts +53 -0
package/package.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bolttech/form-engine-core",
|
|
3
|
+
"version": "0.0.1-beta.1",
|
|
4
|
+
"module": "./index.esm.js",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./index.esm.js",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@gaignoux/currency": "1.1.0",
|
|
9
|
+
"credit-card-type": "10.0.0",
|
|
10
|
+
"lodash": "4.17.21",
|
|
11
|
+
"rxjs": "7.8.1"
|
|
12
|
+
},
|
|
13
|
+
"peerDependencies": {}
|
|
14
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { TFormatters } from '../types/schema';
|
|
2
|
+
/**
|
|
3
|
+
* Formats a credit card number by adding gaps based on the card type.
|
|
4
|
+
*
|
|
5
|
+
* @param {unknown} value - The input value to be formatted, expected to be a string representing a credit card number.
|
|
6
|
+
* @param {TFormatters} formatters - An object containing formatting options.
|
|
7
|
+
* @param {boolean} formatters.gapsCreditCard - A flag indicating whether to apply credit card gap formatting.
|
|
8
|
+
* @returns {unknown} - The formatted credit card number with appropriate gaps, or the original value if formatting is not applied.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const formatters = { gapsCreditCard: true };
|
|
13
|
+
* const result = gapsCreditCard('4111111111111111', formatters);
|
|
14
|
+
* console.log(result); // "4111 1111 1111 1111" (formatted based on card type, e.g., Visa)
|
|
15
|
+
* ```
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const formatters = { gapsCreditCard: false };
|
|
19
|
+
* const result = gapsCreditCard('4111111111111111', formatters);
|
|
20
|
+
* console.log(result); // "4111111111111111" (no formatting applied)
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare const gapsCreditCard: (value: unknown, formatters: TFormatters) => unknown;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { TFormatters } from '../types/schema';
|
|
2
|
+
/**
|
|
3
|
+
* Applies a custom callback function to format a value.
|
|
4
|
+
*
|
|
5
|
+
* @param {unknown} value - The input value to be formatted.
|
|
6
|
+
* @param {TFormatters} formatters - An object containing formatting options.
|
|
7
|
+
* @param {(value: unknown) => unknown} formatters.callback - A custom callback function to apply to the value.
|
|
8
|
+
* @returns {unknown} - The value after applying the custom callback function, or the original value if no callback is provided.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const formatters = { callback: (val) => `Formatted: ${val}` };
|
|
13
|
+
* const result = callback('example', formatters);
|
|
14
|
+
* console.log(result); // "Formatted: example"
|
|
15
|
+
* ```
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const formatters = { callback: (val) => val.toString().toUpperCase() };
|
|
19
|
+
* const result = callback('example', formatters);
|
|
20
|
+
* console.log(result); // "EXAMPLE"
|
|
21
|
+
* ```
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const formatters = { callback: null };
|
|
25
|
+
* const result = callback('example', formatters);
|
|
26
|
+
* console.log(result); // "example" (no formatting applied)
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare const callback: (value: unknown, formatters: TFormatters) => unknown;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { TFormatters } from '../types/schema';
|
|
2
|
+
/**
|
|
3
|
+
* Removes all non-numeric characters from a string.
|
|
4
|
+
*
|
|
5
|
+
* @param value - The value to be processed.
|
|
6
|
+
* @returns The processed value with only numbers.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { onlyNumbers } from './path/to/formatterFunctions';
|
|
11
|
+
*
|
|
12
|
+
* const processedValue = onlyNumbers('abc123def456');
|
|
13
|
+
* console.log(processedValue); // Output: '123456'
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare const onlyNumbers: (value: unknown) => string;
|
|
17
|
+
/**
|
|
18
|
+
* Removes all non-letter characters from a string.
|
|
19
|
+
*
|
|
20
|
+
* @param value - The value to be processed.
|
|
21
|
+
* @returns The processed value with only letters.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* import { onlyLetters } from './path/to/formatterFunctions';
|
|
26
|
+
*
|
|
27
|
+
* const processedValue = onlyLetters('abc123def456');
|
|
28
|
+
* console.log(processedValue); // Output: 'abcdef'
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare const onlyLetters: (value: unknown) => string;
|
|
32
|
+
/**
|
|
33
|
+
* Applies a regular expression pattern to remove matching substrings from a string.
|
|
34
|
+
*
|
|
35
|
+
* @param value - The value to be processed.
|
|
36
|
+
* @param formatters - An object containing formatting options.
|
|
37
|
+
* @returns The processed value with matched substrings removed.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* import { regex } from './path/to/formatterFunctions';
|
|
42
|
+
*
|
|
43
|
+
* const processedValue = regex('abc123def456', { regex: '\\d+' });
|
|
44
|
+
* console.log(processedValue); // Output: 'abcdef'
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare const regex: (value: unknown, formatters: TFormatters) => unknown;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TFormatters } from '../types/schema';
|
|
2
|
+
/**
|
|
3
|
+
* Splits a string by inserting specified values at given positions.
|
|
4
|
+
*
|
|
5
|
+
* @param value - The value to be processed.
|
|
6
|
+
* @param formatters - An object containing formatting options.
|
|
7
|
+
* @returns The processed value with splitters applied.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { splitter } from './path/to/formatterFunctions';
|
|
12
|
+
*
|
|
13
|
+
* const processedValue = splitter('HelloWorld', { splitter: [{ position: 5, value: '_' }] });
|
|
14
|
+
* console.log(processedValue); // Output: 'Hello_World'
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare const splitter: (value: unknown, formatters: TFormatters) => unknown;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { TFormatters } from '../types/schema';
|
|
2
|
+
/**
|
|
3
|
+
* Capitalizes the first letter of a string.
|
|
4
|
+
*
|
|
5
|
+
* @param value - The value to be capitalized.
|
|
6
|
+
* @returns The value with the first letter capitalized.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { capitalize } from './path/to/formatterFunctions';
|
|
11
|
+
*
|
|
12
|
+
* const capitalizedValue = capitalize('hello world');
|
|
13
|
+
* console.log(capitalizedValue); // Output: 'Hello world'
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare const capitalize: (value: unknown) => string;
|
|
17
|
+
/**
|
|
18
|
+
* Converts a string to uppercase.
|
|
19
|
+
*
|
|
20
|
+
* @param value - The value to be converted.
|
|
21
|
+
* @returns The value in uppercase.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* import { uppercase } from './path/to/formatterFunctions';
|
|
26
|
+
*
|
|
27
|
+
* const uppercasedValue = uppercase('hello world');
|
|
28
|
+
* console.log(uppercasedValue); // Output: 'HELLO WORLD'
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare const uppercase: (value: unknown) => string;
|
|
32
|
+
/**
|
|
33
|
+
* Formats a string as a float number with a specific precision and decimal separator.
|
|
34
|
+
*
|
|
35
|
+
* @param value - The value to be formatted.
|
|
36
|
+
* @param formatters - An object containing formatting options.
|
|
37
|
+
* @returns The formatted float number.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* import { onlyFloatNumber } from './path/to/formatterFunctions';
|
|
42
|
+
*
|
|
43
|
+
* const formattedNumber = onlyFloatNumber('1234567.89', { onlyFloatNumber: { precision: 2, decimal: '.' } });
|
|
44
|
+
* console.log(formattedNumber); // Output: '1234567.89'
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare const onlyFloatNumber: (value: unknown, formatters: TFormatters) => unknown;
|
|
48
|
+
/**
|
|
49
|
+
* Trims whitespace from the beginning and end of a string.
|
|
50
|
+
*
|
|
51
|
+
* @param value - The value to be trimmed.
|
|
52
|
+
* @param formatters - An object containing formatting options.
|
|
53
|
+
* @returns The trimmed value.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* import { trim } from './path/to/formatterFunctions';
|
|
58
|
+
*
|
|
59
|
+
* const trimmedValue = trim(' hello world ');
|
|
60
|
+
* console.log(trimmedValue); // Output: 'hello world'
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare const trim: (value: unknown, formatters: TFormatters) => unknown;
|
|
64
|
+
/**
|
|
65
|
+
* Truncates the input value to a specified maximum length if necessary.
|
|
66
|
+
*
|
|
67
|
+
* @param {string | number} value - The input value to be formatted.
|
|
68
|
+
* @param {TFormatters} formatters - An object containing formatting options.
|
|
69
|
+
* @param {number} formatters.maxLength - The maximum allowed length for the input value.
|
|
70
|
+
* @returns {string | number} - The formatted value truncated to the maximum length, if applicable.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const result = maxLength('Hello, World!', { maxLength: 5 });
|
|
75
|
+
* console.log(result); // "Hello"
|
|
76
|
+
* ```
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const result = maxLength(123456789, { maxLength: 4 });
|
|
80
|
+
* console.log(result); // "1234"
|
|
81
|
+
* ```
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* const result = maxLength('Short', { maxLength: 10 });
|
|
85
|
+
* console.log(result); // "Short" (no truncation since input is shorter than maxLength)
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export declare const maxLength: (value: string | number, formatters: TFormatters) => string | number;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the properties of a credit card type.
|
|
3
|
+
*/
|
|
4
|
+
export interface ICreditCardType {
|
|
5
|
+
/**
|
|
6
|
+
* A human-readable name for the credit card type.
|
|
7
|
+
* For example, "Visa", "Mastercard", "American Express", etc.
|
|
8
|
+
*/
|
|
9
|
+
niceType: string;
|
|
10
|
+
/**
|
|
11
|
+
* A unique identifier for the credit card type.
|
|
12
|
+
* Typically, follows industry standards such as "visa", "mastercard", "amex", etc.
|
|
13
|
+
*/
|
|
14
|
+
type: string;
|
|
15
|
+
/**
|
|
16
|
+
* An array of patterns (regular expressions) that match valid card numbers for this type.
|
|
17
|
+
* Each pattern corresponds to a specific length of card number.
|
|
18
|
+
*/
|
|
19
|
+
patterns: number[] | [number[]];
|
|
20
|
+
/**
|
|
21
|
+
* An array representing the positions in the card number where spaces (gaps) should be added
|
|
22
|
+
* to format the number nicely. These positions are counted from the beginning of the number.
|
|
23
|
+
*/
|
|
24
|
+
gaps: number[];
|
|
25
|
+
/**
|
|
26
|
+
* An array of possible lengths for valid card numbers of this type.
|
|
27
|
+
* Typically, this array contains only one element, but some card types may have multiple lengths.
|
|
28
|
+
*/
|
|
29
|
+
lengths: number[];
|
|
30
|
+
/**
|
|
31
|
+
* Information about the card's security code (CVV/CVC/CID).
|
|
32
|
+
*/
|
|
33
|
+
code: {
|
|
34
|
+
/**
|
|
35
|
+
* The size (length) of the security code for this card type.
|
|
36
|
+
*/
|
|
37
|
+
size: number;
|
|
38
|
+
/**
|
|
39
|
+
* A descriptive name for the security code, such as "CVV" or "CVC".
|
|
40
|
+
*/
|
|
41
|
+
name: string;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* An optional value representing the match strength of the card type detection.
|
|
45
|
+
* Higher values indicate stronger matches, while lower values indicate weaker matches.
|
|
46
|
+
* This property is typically provided by the credit card type detection library.
|
|
47
|
+
*/
|
|
48
|
+
matchStrength?: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Represents the return type of the `getTypeCard` function.
|
|
52
|
+
*/
|
|
53
|
+
export type TGetTypeCard = [ICreditCardType, string];
|
|
54
|
+
/**
|
|
55
|
+
* Retrieves the type of the credit card and the raw value without spaces.
|
|
56
|
+
*
|
|
57
|
+
* @param value - The credit card number as a string.
|
|
58
|
+
* @param availableOptions - An optional array of credit card types to consider.
|
|
59
|
+
* @returns An array containing the detected credit card type and the raw value without spaces.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* import { getTypeCard } from './path/to/helperFunctions';
|
|
64
|
+
*
|
|
65
|
+
* const [creditCardType, rawValue] = getTypeCard('4111 1111 1111 1111');
|
|
66
|
+
* console.log(creditCardType); // Output: { niceType: 'Visa', type: 'visa', ... }
|
|
67
|
+
* console.log(rawValue); // Output: '4111111111111111'
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare const getTypeCard: (value: string, availableOptions?: string[]) => TGetTypeCard;
|
|
71
|
+
/**
|
|
72
|
+
* Formats a credit card number according to its type's gaps and lengths.
|
|
73
|
+
*
|
|
74
|
+
* @param value - The credit card number as a string.
|
|
75
|
+
* @param type - The type of the credit card.
|
|
76
|
+
* @returns The formatted credit card number.
|
|
77
|
+
*/
|
|
78
|
+
export declare const formatValue: (value: string, type: ICreditCardType) => string;
|
|
79
|
+
/**
|
|
80
|
+
* Formats a date string by adding a prefix and/or trimming the string based on its length.
|
|
81
|
+
*
|
|
82
|
+
* @param value - The date string to be formatted.
|
|
83
|
+
* @param end - The ending index to slice the string to.
|
|
84
|
+
* @param prefix - The prefix to add between date components.
|
|
85
|
+
* @returns The formatted date string.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* import { formatDateCard } from './path/to/helperFunctions';
|
|
90
|
+
*
|
|
91
|
+
* const formattedDate = formatDateCard('1223', 4, '/');
|
|
92
|
+
* console.log(formattedDate); // Output: '12/23'
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export declare const formatDateCard: (value: string, end?: number, prefix?: string) => string;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { TSubscribedTemplates } from '../types/template';
|
|
3
|
+
import { OutgoingHttpHeaders } from 'http2';
|
|
4
|
+
/**
|
|
5
|
+
* Makes an HTTP request using XMLHttpRequest.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} method - The HTTP method (GET, POST, PUT, DELETE, etc.).
|
|
8
|
+
* @param {string} url - The URL to which the request is sent.
|
|
9
|
+
* @param {OutgoingHttpHeaders} [headers] - Optional request headers.
|
|
10
|
+
* @param {Record<string,unknown>} [body] - Optional object body.
|
|
11
|
+
* @returns {Promise<string>} A promise that resolves with the response text if the request is successful, otherwise rejects with an error message.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const response = await makeRequest('GET', 'https://api.example.com/data');
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
declare function makeRequest(method: string, url: string, headers?: OutgoingHttpHeaders, body?: Record<string, unknown>): Promise<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Extracts keys enclosed in `${}` from a given expression.
|
|
21
|
+
*
|
|
22
|
+
* @param {string} expression - The expression to extract keys from.
|
|
23
|
+
* @returns {
|
|
24
|
+
* originFieldKeys: string[];
|
|
25
|
+
* originPropertyKeys: string[];
|
|
26
|
+
* } An object containing the field names and properties from the template expression.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const keys = extractFieldKeys('Hello ${name.value}, your age is ${age.props.label}.');
|
|
31
|
+
* // keys will be {originFieldKeys:['name', 'age'],originPropertyKeys:[value,props]}
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
declare function extractFieldKeys(expression: string): {
|
|
35
|
+
originFieldKeys: string[];
|
|
36
|
+
originPropertyKeys: string[];
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Traverses an object and extracts expressions containing keys.
|
|
40
|
+
*
|
|
41
|
+
* @param {any} obj - The object to traverse.
|
|
42
|
+
* @param {string} [path] - Optional path within the object (used internally during recursion).
|
|
43
|
+
* @returns {TSubscribedTemplates[]} An array of extracted expressions along with their keys and paths.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const data = {
|
|
48
|
+
* user: {
|
|
49
|
+
* name: 'John',
|
|
50
|
+
* age: 30,
|
|
51
|
+
* address: {
|
|
52
|
+
* street: '123 Main St',
|
|
53
|
+
* city: 'Example City'
|
|
54
|
+
* }
|
|
55
|
+
* },
|
|
56
|
+
* message: 'Hello ${user.name}, your age is ${user.age}.'
|
|
57
|
+
* };
|
|
58
|
+
*
|
|
59
|
+
* const expressions = traverseObject(data);
|
|
60
|
+
* // expressions will contain an array of objects with origin expressions, field keys, and destination paths.
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
declare function traverseObject(obj: any, path?: string): TSubscribedTemplates[];
|
|
64
|
+
export { makeRequest, traverseObject, extractFieldKeys };
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './types/event';
|
|
2
|
+
export * from './types/form';
|
|
3
|
+
export * from './types/schema';
|
|
4
|
+
export * from './types/template';
|
|
5
|
+
export * from './types/mapper';
|
|
6
|
+
export * from './interfaces/schema';
|
|
7
|
+
export * from './interfaces/state';
|
|
8
|
+
export * from './managers/form';
|
|
9
|
+
export * from './managers/formGroup';
|
|
10
|
+
export * from './managers/field';
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { TApiEvent, TErrorMessages, TEvent, TFormatters, TMasks, TProps, TResetValueMethods, TValidationMethods, TVisibility } from '../types/schema';
|
|
2
|
+
/**
|
|
3
|
+
* @interface IComponentSchema
|
|
4
|
+
* Represents the schema for a component within a form.
|
|
5
|
+
*
|
|
6
|
+
* @property {string} component - The type of component (e.g., 'input', 'button').
|
|
7
|
+
* @property {TProps} props - The properties of the component.
|
|
8
|
+
* @property {string} name - The name of the component.
|
|
9
|
+
* @property {TEvent<TValidationMethods>} [validations] - The validation methods for the component.
|
|
10
|
+
* @property {TVisibility[]} [visibilityConditions] - The visibility conditions for the component.
|
|
11
|
+
* @property {TResetValueMethods[]} [resetValues] - The reset value methods for the component.
|
|
12
|
+
* @property {TErrorMessages} [errorMessages] - The error messages for the component.
|
|
13
|
+
* @property {TApiEvent} [api] - The API configuration for the component.
|
|
14
|
+
* @property {TFormatters} [formatters] - The formatters for the component.
|
|
15
|
+
* @property {TMasks} [masks] - The masks for the component.
|
|
16
|
+
* @property {IComponentSchema[]} [children] - The child components.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const schema: IComponentSchema = {
|
|
21
|
+
* component: 'input',
|
|
22
|
+
* props: { type: 'text', placeholder: 'Enter your name' },
|
|
23
|
+
* name: 'name',
|
|
24
|
+
* validations: { config: { required: true }, events: [{ eventName: 'ON_FIELD_BLUR' }] },
|
|
25
|
+
* visibilityConditions: [{ conditions: { field: 'age', value: 18 } }],
|
|
26
|
+
* resetValues: [{ field: 'age', resetTo: '' }],
|
|
27
|
+
* errorMessages: { required: 'This field is required.' },
|
|
28
|
+
* api: { defaultConfig: { config: { method: 'POST', url: 'https://api.example.com/submit' }, events: [{ eventName: 'ON_FORM_SUBMIT' }] } },
|
|
29
|
+
* formatters: { capitalize: true },
|
|
30
|
+
* masks: { currency: { align: 'left', decimal: '.', precision: 2, prefix: '$', thousands: ',' } },
|
|
31
|
+
* children: []
|
|
32
|
+
* };
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
interface IComponentSchema {
|
|
36
|
+
component: string;
|
|
37
|
+
props?: TProps;
|
|
38
|
+
name: string;
|
|
39
|
+
validations?: TEvent<TValidationMethods>;
|
|
40
|
+
api?: TApiEvent;
|
|
41
|
+
visibilityConditions?: TVisibility[];
|
|
42
|
+
resetValues?: TResetValueMethods[];
|
|
43
|
+
errorMessages?: TErrorMessages;
|
|
44
|
+
formatters?: TFormatters;
|
|
45
|
+
masks?: TMasks;
|
|
46
|
+
children?: IComponentSchema[];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* @interface IFormSchema
|
|
50
|
+
* Represents the schema for a form.
|
|
51
|
+
*
|
|
52
|
+
* @property {string} index - The unique index or identifier for the form.
|
|
53
|
+
* @property {string} [action] - The URL to which the form data will be submitted.
|
|
54
|
+
* @property {string} [method] - The HTTP method used to submit the form (e.g., 'POST', 'GET').
|
|
55
|
+
* @property {Record<string, unknown>} [initialValues] - The initial values for the form fields.
|
|
56
|
+
* @property {Record<string, unknown>} [iVars] - Dynamic key value pairs that change from any external source
|
|
57
|
+
* @property {IComponentSchema[]} [components] - The list of components included in the form.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const formSchema: IFormSchema = {
|
|
62
|
+
* index: 'userForm',
|
|
63
|
+
* action: 'https://api.example.com/submit',
|
|
64
|
+
* method: 'POST',
|
|
65
|
+
* initialValues: { name: '', email: '' },
|
|
66
|
+
* iVars: iVarsState,
|
|
67
|
+
* components: [
|
|
68
|
+
* { component: 'input', name: 'name', props: { placeholder: 'Enter your name' } },
|
|
69
|
+
* { component: 'input', name: 'email', props: { placeholder: 'Enter your email' } }
|
|
70
|
+
* ]
|
|
71
|
+
* };
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
interface IFormSchema {
|
|
75
|
+
index: string;
|
|
76
|
+
action?: string;
|
|
77
|
+
method?: string;
|
|
78
|
+
initialValues?: Record<string, unknown>;
|
|
79
|
+
iVars?: Record<string, unknown>;
|
|
80
|
+
components?: IComponentSchema[];
|
|
81
|
+
}
|
|
82
|
+
export { IFormSchema, IComponentSchema };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { TApiResponse } from '../types/schema';
|
|
2
|
+
/**
|
|
3
|
+
* @interface IState
|
|
4
|
+
* Represents the state of a form component.
|
|
5
|
+
*
|
|
6
|
+
* @property {string[]} errors - The list of error messages.
|
|
7
|
+
* @property {boolean} visibility - The visibility state of the component.
|
|
8
|
+
* @property {TApiResponse} apiResponse - The API response data.
|
|
9
|
+
* @property {Record<string, unknown>} props - The properties of the component.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const state: IState = {
|
|
14
|
+
* errors: ['This field is required.'],
|
|
15
|
+
* visibility: true,
|
|
16
|
+
* apiResponse: { default: { response: null } },
|
|
17
|
+
* props: { type: 'text', value: 'John' }
|
|
18
|
+
* };
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
interface IState {
|
|
22
|
+
errors: string[];
|
|
23
|
+
visibility: boolean;
|
|
24
|
+
apiResponse: TApiResponse;
|
|
25
|
+
props: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
export { IState };
|