@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.
Files changed (40) hide show
  1. package/index.esm.d.ts +1 -0
  2. package/index.esm.js +3518 -0
  3. package/package.json +14 -0
  4. package/src/formatters/creditCard.d.ts +23 -0
  5. package/src/formatters/custom.d.ts +29 -0
  6. package/src/formatters/handler.d.ts +2 -0
  7. package/src/formatters/regex.d.ts +47 -0
  8. package/src/formatters/splitter.d.ts +17 -0
  9. package/src/formatters/string.d.ts +88 -0
  10. package/src/helpers/creditCard.d.ts +95 -0
  11. package/src/helpers/helpers.d.ts +64 -0
  12. package/src/index.d.ts +10 -0
  13. package/src/interfaces/schema.d.ts +82 -0
  14. package/src/interfaces/state.d.ts +27 -0
  15. package/src/managers/field.d.ts +294 -0
  16. package/src/managers/form.d.ts +224 -0
  17. package/src/managers/formGroup.d.ts +64 -0
  18. package/src/masks/creditCard.d.ts +60 -0
  19. package/src/masks/generic.d.ts +39 -0
  20. package/src/masks/handler.d.ts +2 -0
  21. package/src/masks/string.d.ts +97 -0
  22. package/src/types/event.d.ts +43 -0
  23. package/src/types/form.d.ts +51 -0
  24. package/src/types/mapper.d.ts +94 -0
  25. package/src/types/schema.d.ts +742 -0
  26. package/src/types/template.d.ts +32 -0
  27. package/src/types/utility.d.ts +4 -0
  28. package/src/validations/creditCard.d.ts +52 -0
  29. package/src/validations/custom.d.ts +25 -0
  30. package/src/validations/date.d.ts +78 -0
  31. package/src/validations/document.d.ts +25 -0
  32. package/src/validations/handler.d.ts +2 -0
  33. package/src/validations/length.d.ts +39 -0
  34. package/src/validations/list.d.ts +32 -0
  35. package/src/validations/logical.d.ts +75 -0
  36. package/src/validations/multiple.d.ts +31 -0
  37. package/src/validations/number.d.ts +115 -0
  38. package/src/validations/object.d.ts +44 -0
  39. package/src/validations/regex.d.ts +217 -0
  40. package/src/validations/string.d.ts +53 -0
@@ -0,0 +1,97 @@
1
+ import { TMasks } from '../types/schema';
2
+ /**
3
+ * Replaces all characters in a string with a specified replacement string or character.
4
+ *
5
+ * @param value - The value to be masked.
6
+ * @param masks - An object containing the mask configuration.
7
+ * @returns The masked value.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { replaceAll } from './path/to/maskFunctions';
12
+ *
13
+ * const masks = { replaceAll: '*' };
14
+ *
15
+ * const maskedValue = replaceAll('12345', masks);
16
+ * console.log(maskedValue); // Output: '*****'
17
+ *
18
+ * // Using from a JSON config
19
+ * const config = {
20
+ * value: 'hello',
21
+ * masks: { replaceAll: '*' }
22
+ * };
23
+ *
24
+ * const maskedValue = replaceAll(config.value, config.masks);
25
+ * console.log(maskedValue); // Output: '*****'
26
+ * ```
27
+ */
28
+ export declare const replaceAll: (value: string | number, masks: TMasks) => unknown;
29
+ /**
30
+ * Formats a numeric value as a currency string based on the provided mask configuration.
31
+ *
32
+ * @param value - The numeric value to be formatted.
33
+ * @param masks - An object containing the mask configuration.
34
+ * @returns The formatted currency string.
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * import { currency } from './path/to/maskFunctions';
39
+ *
40
+ * const masks = {
41
+ * currency: {
42
+ * align: 'right',
43
+ * decimal: ',',
44
+ * precision: 2,
45
+ * prefix: 'USD',
46
+ * thousands: '.'
47
+ * }
48
+ * };
49
+ *
50
+ * const formattedValue = currency(12345.67, masks);
51
+ * console.log(formattedValue); // Output: '12.345,67 $'
52
+ *
53
+ * // Using from a JSON config
54
+ * const config = {
55
+ * value: 9876.54,
56
+ * masks: {
57
+ * currency: {
58
+ * align: 'right',
59
+ * decimal: ',',
60
+ * precision: 2,
61
+ * prefix: 'EUR',
62
+ * thousands: '.'
63
+ * }
64
+ * }
65
+ * };
66
+ *
67
+ * const formattedValue = currency(config.value, config.masks);
68
+ * console.log(formattedValue); // Output: '9.876,54 €'
69
+ * ```
70
+ */
71
+ export declare const currency: (value: string | number, masks: TMasks) => unknown;
72
+ /**
73
+ * Applies a custom mask to a string based on the provided mask configuration.
74
+ *
75
+ * @param value - The value to be masked.
76
+ * @param masks - An object containing the mask configuration.
77
+ * @returns The masked value.
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * import { custom } from './path/to/maskFunctions';
82
+ *
83
+ * const masks = { custom: '##-##' };
84
+ *
85
+ * const maskedValue = custom('123456', masks);
86
+ * console.log(maskedValue); // Output: '12-34'
87
+ *
88
+ * // Using from a JSON config
89
+ * const config = {
90
+ * masks: { custom: '###-###' }
91
+ * };
92
+ *
93
+ * const maskedValue = custom(config.value, config.masks);
94
+ * console.log(maskedValue); // Output: '987-654'
95
+ * ```
96
+ */
97
+ export declare const custom: (value: string, masks: TMasks) => string;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @type TEvents
3
+ * Represents the different types of events that can occur on form fields.
4
+ *
5
+ * @example
6
+ * ```typescript
7
+ * const event: TEvents = 'ON_FIELD_CHANGE';
8
+ * ```
9
+ */
10
+ 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
+ /**
12
+ * @type TMutationEvents
13
+ * Represents the different types of events that can occur internally that triggers templating.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const event: TMutationEvents = 'ON_VALUE';
18
+ * ```
19
+ */
20
+ type TMutationEvents = 'ON_VALUE' | 'ON_PROPS' | 'ON_VISIBILITY' | 'ON_API' | 'ON_IVARS' | 'ON_FIELDS';
21
+ declare enum TMutationEnum {
22
+ ON_VALUE = "value",
23
+ ON_PROPS = "props",
24
+ ON_VISIBILITY = "visibility",
25
+ ON_API = "api",
26
+ ON_IVARS = "iVars",
27
+ ON_FIELDS = "fields"
28
+ }
29
+ /**
30
+ * @type TValueChangeEvent
31
+ * Represents the custom change handle function to perform value changes.
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * handleChangeEvent (value, opts) {
36
+ * return value
37
+ * }
38
+ * ```
39
+ */
40
+ type TValueChangeEvent = (value: unknown, opts?: {
41
+ props: Record<string, unknown>;
42
+ }) => void;
43
+ export { TEvents, TMutationEvents, TMutationEnum, TValueChangeEvent };
@@ -0,0 +1,51 @@
1
+ import { IFormSchema } from '../interfaces/schema';
2
+ import { TMapper } from './mapper';
3
+ /**
4
+ * @type TFormValues
5
+ * Represents the values and state of a form.
6
+ *
7
+ * @property {Record<string, unknown>} values - The current values of the form fields.
8
+ * @property {string[]} erroredFields - A list of field names that have errors.
9
+ * @property {boolean} isValid - Indicates whether the form is valid.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const formValues: TFormValues = {
14
+ * values: { name: 'John', age: 30 },
15
+ * erroredFields: ['email'],
16
+ * isValid: false
17
+ * };
18
+ * ```
19
+ */
20
+ type TFormValues = {
21
+ values: Record<string, unknown>;
22
+ erroredFields: string[];
23
+ isValid: boolean;
24
+ };
25
+ /**
26
+ * @type TFormEntry
27
+ * Represents the entry configuration for a form.
28
+ *
29
+ * @property {IFormSchema} [schema] - The schema defining the structure and behavior of the form.
30
+ * @property {Record<string, unknown>} [initialValues] - The initial values for the form fields.
31
+ * @property {(data: TFormValues) => void} [onSubmit] - Callback function to handle form submission.
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * const formEntry: TFormEntry = {
36
+ * schema: [{ component: 'input', props: {}, name: 'name' }],
37
+ * initialValues: { name: 'John' },
38
+ * onSubmit: (data) => { console.log(data); }
39
+ * };
40
+ * ```
41
+ */
42
+ type TFormEntry = Omit<IFormSchema, 'components'> & {
43
+ schema?: IFormSchema;
44
+ onSubmit?: (data: TFormValues) => void;
45
+ onData?: (payload: {
46
+ field: string;
47
+ data: TFormValues;
48
+ }) => void;
49
+ mappers: TMapper<unknown>[];
50
+ };
51
+ export { TFormValues, TFormEntry };
@@ -0,0 +1,94 @@
1
+ import { TValueChangeEvent } from './event';
2
+ import { OneOf } from './utility';
3
+ /**
4
+ * @type TComponentPropsMapping
5
+ * Represents the mapping of component properties for various events and actions.
6
+ *
7
+ * @property {string} [getValue] - Function to get the value.
8
+ * @property {string} [setValue] - Function to set the value.
9
+ * @property {string} [onBlur] - Function to handle the blur event.
10
+ * @property {string} [onClick] - Function to handle the click event.
11
+ * @property {string} [onFocus] - Function to handle the focus event.
12
+ * @property {string} [onKeyUp] - Function to handle the keyup event.
13
+ * @property {string} [onKeyDown] - Function to handle the keydown event.
14
+ * @property {string} [setErrorMessage] - Function to set the error message.
15
+ * @property {string} [setErrorState] - Function to set the error state.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const componentProps: TComponentPropsMapping = {
20
+ * getValue: 'getValueFunction',
21
+ * setValue: 'setValueFunction',
22
+ * onBlur: 'handleBlur',
23
+ * onClick: 'handleClick',
24
+ * onFocus: 'handleFocus',
25
+ * onKeyUp: 'handleKeyUp',
26
+ * onKeyDown: 'handleKeyDown',
27
+ * setErrorMessage: 'setErrorMessageFunction',
28
+ * setErrorState: 'setErrorStateFunction'
29
+ * };
30
+ * ```
31
+ */
32
+ type TComponentPropsMapping = {
33
+ getValue?: string;
34
+ setValue?: string;
35
+ onBlur?: string;
36
+ onClick?: string;
37
+ onFocus?: string;
38
+ onKeyUp?: string;
39
+ onKeyDown?: string;
40
+ setErrorMessage?: string;
41
+ setErrorState?: string;
42
+ };
43
+ /**
44
+ * @type TMapper
45
+ * Represents the mapping of a component, including the component type,
46
+ * name, events, and an optional function to handle value changes.
47
+ *
48
+ * @property {ElementType} component - The type of the component.
49
+ * @property {string} componentName - The name of the component.
50
+ * @property {TComponentPropsMapping} [events] - Mapping event properties for the component.
51
+ * @property {TValueChangeEvent} [valueChangeEvent] - Optional function to handle value changes.
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * const mappers: TMapper[] = [
56
+ * {
57
+ * component: InputElement,
58
+ * componentName: 'input',
59
+ * events: {
60
+ * getValue: 'onChange2',
61
+ * onBlur: 'onBlur2',
62
+ * onFocus: 'onFocus2',
63
+ * }
64
+ * },
65
+ * {
66
+ * component: Container,
67
+ * componentName: 'row',
68
+ * },
69
+ * {
70
+ * component: Dropdown,
71
+ * componentName: 'dropdown',
72
+ * valueChangeEvent: (event: {
73
+ * id: string;
74
+ * label: string;
75
+ * value: string;
76
+ * }) => ({ _value: event.value, _stateValue: event.id }),
77
+ * },
78
+ * {
79
+ * component: DatePicker,
80
+ * componentName: 'datepicker',
81
+ * valueChangeEvent: (event: string) => event,
82
+ * },
83
+ * ];
84
+ * ```
85
+ */
86
+ type TMapper<T> = {
87
+ componentName: string;
88
+ events?: TComponentPropsMapping;
89
+ valueChangeEvent?: TValueChangeEvent;
90
+ } & OneOf<{
91
+ component: T;
92
+ asynccomponent: T;
93
+ }>;
94
+ export { TMapper, TComponentPropsMapping };