@bolttech/form-engine-core 1.0.10 → 1.1.0

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 (64) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/credit-card.d.ts +743 -0
  3. package/credit-card.esm.js +1 -0
  4. package/currency.d.ts +131 -0
  5. package/currency.esm.js +1 -0
  6. package/date.d.ts +582 -0
  7. package/date.esm.js +1 -0
  8. package/document.d.ts +527 -0
  9. package/document.esm.js +1 -0
  10. package/index.d.ts +52 -5
  11. package/index.esm.js +1 -4570
  12. package/lite.d.ts +2393 -0
  13. package/lite.esm.js +1 -0
  14. package/package.json +34 -2
  15. package/src/constants/constants.d.ts +11 -0
  16. package/src/formatters/creditCard.d.ts +23 -0
  17. package/src/formatters/custom.d.ts +29 -0
  18. package/src/formatters/handler.d.ts +2 -0
  19. package/src/formatters/regex.d.ts +47 -0
  20. package/src/formatters/splitter.d.ts +17 -0
  21. package/src/formatters/string.d.ts +88 -0
  22. package/src/helpers/SafeSubject.d.ts +21 -0
  23. package/src/helpers/creditCard.d.ts +95 -0
  24. package/src/helpers/helpers.d.ts +66 -0
  25. package/src/helpers/lodash-replacements.d.ts +41 -0
  26. package/src/helpers/validation.d.ts +28 -0
  27. package/src/index.d.ts +15 -0
  28. package/src/interfaces/schema.d.ts +161 -0
  29. package/src/interfaces/state.d.ts +22 -0
  30. package/src/lite.d.ts +30 -0
  31. package/src/managers/field.d.ts +339 -0
  32. package/src/managers/form.d.ts +357 -0
  33. package/src/managers/formGroup.d.ts +110 -0
  34. package/src/managers/index.d.ts +3 -0
  35. package/src/masks/creditCard.d.ts +60 -0
  36. package/src/masks/currency.d.ts +29 -0
  37. package/src/masks/generic.d.ts +39 -0
  38. package/src/masks/handler.d.ts +2 -0
  39. package/src/masks/string.d.ts +37 -0
  40. package/src/plugins/credit-card.d.ts +4 -0
  41. package/src/plugins/currency.d.ts +2 -0
  42. package/src/plugins/date.d.ts +2 -0
  43. package/src/plugins/document.d.ts +2 -0
  44. package/src/registry.d.ts +20 -0
  45. package/src/types/event.d.ts +175 -0
  46. package/src/types/form.d.ts +55 -0
  47. package/src/types/mapper.d.ts +87 -0
  48. package/src/types/schema.d.ts +1001 -0
  49. package/src/types/template.d.ts +65 -0
  50. package/src/types/utility.d.ts +12 -0
  51. package/src/validations/creditCard.d.ts +52 -0
  52. package/src/validations/custom.d.ts +27 -0
  53. package/src/validations/date.d.ts +79 -0
  54. package/src/validations/document.d.ts +25 -0
  55. package/src/validations/handler.d.ts +2 -0
  56. package/src/validations/length.d.ts +39 -0
  57. package/src/validations/list.d.ts +32 -0
  58. package/src/validations/logical.d.ts +75 -0
  59. package/src/validations/multiple.d.ts +31 -0
  60. package/src/validations/namedRule.d.ts +22 -0
  61. package/src/validations/number.d.ts +145 -0
  62. package/src/validations/object.d.ts +44 -0
  63. package/src/validations/regex.d.ts +217 -0
  64. package/src/validations/string.d.ts +53 -0
@@ -0,0 +1,175 @@
1
+ import { IFormField } from '../managers';
2
+ import { TFormValues } from './form';
3
+ /**
4
+ * @type TEventEnum
5
+ * Represents the different types of events that can occur on form fields.
6
+ * @property {never} ON_FIELD_MOUNT - when field mounts on page
7
+ * @property {never} ON_FIELD_UNMOUNT - when field unmounts on page (also triggered when form is unmounted from page)
8
+ * @property {never} ON_FIELD_CHANGE - when field changes value by user inout
9
+ * @property {never} ON_FIELD_BLUR - when field is blurred
10
+ * @property {never} ON_FIELD_FOCUS - when field is focused
11
+ * @property {never} ON_FIELD_CLICK - when field is clicked
12
+ * @property {never} ON_FIELD_KEYUP - when the pressing key button on field is lifted up
13
+ * @property {never} ON_FIELD_KEYDOWN - when a key button on field is pressed down
14
+ * @property {never} ON_FIELD_CLEARED - when a field was changed with a resetValues rule
15
+ * @property {never} ON_FORM_SUBMIT - when the form is submitted (only type="submit" buttons)
16
+ * @property {never} ON_FIELD_VALIDATION - when a field is validaded by a validation rule
17
+ * @property {never} ON_FORM_MOUNT - emitted when the form mounts
18
+ * @property {never} ON_API_FIELD_REQUEST - emitted when an api request from schema is called
19
+ * @property {never} ON_API_FIELD_RESPONSE - emitted when an api response from schema is received
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const event: TEvents = 'ON_FIELD_CHANGE';
24
+ * ```
25
+ */
26
+ type TEventEnum = {
27
+ ON_FIELD_MOUNT: never;
28
+ ON_FIELD_UNMOUNT: never;
29
+ ON_FIELD_CHANGE: never;
30
+ ON_FIELD_BLUR: never;
31
+ ON_FIELD_FOCUS: never;
32
+ ON_FIELD_CLICK: never;
33
+ ON_FIELD_KEYUP: never;
34
+ ON_FIELD_KEYDOWN: never;
35
+ ON_FIELD_CLEARED: never;
36
+ ON_FORM_SUBMIT: never;
37
+ ON_FIELD_VALIDATION: never;
38
+ ON_FORM_MOUNT: never;
39
+ ON_API_FIELD_REQUEST: never;
40
+ ON_API_FIELD_RESPONSE: never;
41
+ };
42
+ type TEvents = keyof TEventEnum;
43
+ /**
44
+ * Represents the possible event properties for form fields callbacks.
45
+ * * Represents a mapping of event properties to their corresponding callback functions.
46
+ * @property {string} onChange - trigger bind component change event
47
+ * @property {string} onBlur - trigger bind component blur event
48
+ * @property {string} onFocus - trigger bind component focus event
49
+ * @property {string} onKeyDown - trigger bind component keydown event
50
+ * @property {string} onKeyUp - trigger bind component keyup event
51
+ * @property {string} onMount - triggered on field mount
52
+ * @property {string} onApiResponse - triggered when schema api call is completed
53
+ * @property {string} onApiRequest - triggered when schema api call starts
54
+ * @property {string} onClick - trigger bind component keyup event
55
+ * @property {string} onCleared - triggered when a resetValue rule apply on the target field
56
+ * @property {string} onUnmount - triggered when a field unmounts
57
+ */
58
+ type TEventPropsEnum = {
59
+ onChange: never;
60
+ onBlur: never;
61
+ onFocus: never;
62
+ onKeyDown: never;
63
+ onKeyUp: never;
64
+ onMount: never;
65
+ onApiResponse: never;
66
+ onApiRequest: never;
67
+ onClick: never;
68
+ onCleared: never;
69
+ onUnmount: never;
70
+ };
71
+ type TEventProps = keyof TEventPropsEnum;
72
+ type TEventDataPropsEnum = {
73
+ onFormMount: never;
74
+ onData: never;
75
+ onSubmit: never;
76
+ onValid: never;
77
+ };
78
+ type TEventDataProps = keyof TEventDataPropsEnum;
79
+ /**
80
+ * @type TMutationEvents
81
+ * Represents the different types of events that can occur internally that triggers templating.
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * const event: TMutationEvents = 'ON_VALUE';
86
+ * ```
87
+ */
88
+ type TMutationEvents = 'ON_VALUE' | 'ON_PROPS' | 'ON_VISIBILITY' | 'ON_API_REQUEST' | 'ON_API_RESPONSE' | 'ON_IVARS' | 'ON_FIELDS' | 'ON_RESET' | 'ON_FORM';
89
+ declare enum TMutationEnum {
90
+ ON_VALUE = "value",
91
+ ON_PROPS = "props",
92
+ ON_VISIBILITY = "visibility",
93
+ ON_API = "api",
94
+ ON_IVARS = "iVars",
95
+ ON_FIELDS = "fields"
96
+ }
97
+ /**
98
+ * @type TValueChangeEvent
99
+ * Represents the custom change handle function to perform value changes.
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * handleChangeEvent (value, opts) {
104
+ * return value
105
+ * }
106
+ * ```
107
+ */
108
+ type TValueChangeEvent = (value: unknown, opts?: {
109
+ props: Record<string, unknown>;
110
+ }) => void;
111
+ /**
112
+ * @type TFieldEvent
113
+ * Event emitted on all basic form events, except onData
114
+ */
115
+ type TFieldEvent = {
116
+ event: TEvents;
117
+ fieldName: string;
118
+ fieldInstance?: IFormField;
119
+ };
120
+ /**
121
+ * @type TFormDataPayload
122
+ * Event emitted to formGroup instance to capture onData form events
123
+ */
124
+ type TFormDataPayload = {
125
+ formIndex: string;
126
+ fieldIndex: string;
127
+ event: TEvents;
128
+ };
129
+ /**
130
+ * @type TFormSubmitPayload
131
+ * Event emitted to formGroup instance to capture onSubmit form events
132
+ */
133
+ type TFormSubmitPayload<T> = {
134
+ formIndex: string;
135
+ values: TFormValues<T>;
136
+ };
137
+ /**
138
+ * @type TFormValidationPayload
139
+ * Form onValid event emmited payload on callback function parameter
140
+ */
141
+ type TFormValidationPayload = {
142
+ formIndex: string;
143
+ valid: boolean;
144
+ };
145
+ /**
146
+ * @type TFieldValidationPayload
147
+ * field event emmited payload on field validation
148
+ */
149
+ type TFieldValidationPayload = {
150
+ fieldTrigger: string;
151
+ };
152
+ type TFormDataValues<T> = {
153
+ formId: string;
154
+ formField: string;
155
+ values?: TFormValues<T>;
156
+ };
157
+ /**
158
+ * @type TFormGroupOnDataEventPayload
159
+ * Form Group onData event emitted payload on callback function parameter
160
+ */
161
+ type TFormGroupOnDataEventPayload<T> = Record<string, TFormDataValues<T>>;
162
+ /**
163
+ * @type TFormGroupOnValidEventPayload
164
+ * Form Group onValid event emitted payload on callback function parameter
165
+ */
166
+ type TFormGroupOnValidEventPayload = {
167
+ groupValid: boolean;
168
+ forms: Record<string, boolean>;
169
+ };
170
+ /**
171
+ * @type TFormGroupOnSubmitEventPayload
172
+ * Form Group onSubmit event emitted payload on callback function parameter
173
+ */
174
+ type TFormGroupOnSubmitEventPayload<T> = Record<string, TFormValues<T> | undefined>;
175
+ export { TEvents, TEventEnum, TEventProps, TEventPropsEnum, TEventDataProps, TEventDataPropsEnum, TMutationEvents, TMutationEnum, TValueChangeEvent, TFieldEvent, TFormDataPayload, TFormDataValues, TFormSubmitPayload, TFormGroupOnDataEventPayload, TFormGroupOnValidEventPayload, TFormGroupOnSubmitEventPayload, TFormValidationPayload, TFieldValidationPayload, };
@@ -0,0 +1,55 @@
1
+ import { Subject } from 'rxjs';
2
+ import { IFormSchema } from '../interfaces/schema';
3
+ import { TMapper } from './mapper';
4
+ import { TFormDataPayload, TFormSubmitPayload, TFormValidationPayload } from './event';
5
+ /**
6
+ * @type TFormValues<T>
7
+ * 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.
8
+ *
9
+ * @property {Generic Type} values - The current values of the form fields.
10
+ * @property {string[]} erroredFields - A list of field names that have errors.
11
+ * @property {boolean} isValid - Indicates whether the form is valid.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const formValues: TFormValues = {
16
+ * values: { name: 'John', age: 30 },
17
+ * erroredFields: ['email'],
18
+ * isValid: false
19
+ * };
20
+ * ```
21
+ */
22
+ type TFormValues<T> = {
23
+ values: T;
24
+ metadata: unknown;
25
+ erroredFields: string[];
26
+ isValid: boolean;
27
+ };
28
+ /**
29
+ * @type TFormEntry
30
+ * Represents the entry configuration for a form.
31
+ *
32
+ * @property {IFormSchema} [schema] - The schema defining the structure and behavior of the form.
33
+ * @property {Record<string, unknown>} [initialValues] - The initial values for the form fields.
34
+ * @property {(data: TFormValues) => void} [onSubmit] - Callback function to handle form submission.
35
+ * @property {Subject<TFormDataPayload>} [dataSubject$] - data subject passed from formGroup instance
36
+ * @property {Subject<TFormValidationPayload>} [formValidSubject$] - formValid subject passed from formGroup instance
37
+ * @property {Subject<TFormSubmitPayload<unknown>>} [submitSubject$] - submit subject passed from formGroup instance
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * const formEntry: TFormEntry = {
42
+ * schema: [{ component: 'input', props: {}, name: 'name' }],
43
+ * initialValues: { name: 'John' },
44
+ * onSubmit: (data) => { console.log(data); }
45
+ * };
46
+ * ```
47
+ */
48
+ type TFormEntry = Omit<IFormSchema, 'components'> & {
49
+ schema?: IFormSchema;
50
+ mappers?: TMapper<unknown>[];
51
+ dataSubject$?: Subject<TFormDataPayload>;
52
+ formValidSubject$?: Subject<TFormValidationPayload>;
53
+ submitSubject$?: Subject<TFormSubmitPayload<unknown>>;
54
+ };
55
+ export { TFormValues, TFormEntry };
@@ -0,0 +1,87 @@
1
+ import { TEventDataPropsEnum, TEventPropsEnum, TValueChangeEvent } from './event';
2
+ import { OneOf } from './utility';
3
+ type TComponentPropsMappingSubset = keyof (Pick<TEventPropsEnum, 'onBlur' | 'onChange' | 'onFocus' | 'onKeyDown' | 'onKeyUp' | 'onClick'> & Pick<TEventDataPropsEnum, 'onSubmit'>);
4
+ /**
5
+ * @type TComponentPropsMapping
6
+ * Represents the mapping of component properties for various events and actions.
7
+ * @property {string} [getValue] - component function name to get the value.
8
+ * @property {string} [setValue] - component function name to set the value.
9
+ * @property {string} [setErrorMessage] - component function name to set the error message.
10
+ * @property {string} [setErrorState] - component function name to set the error state.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const componentProps: TComponentPropsMapping = {
15
+ * getValue: 'getValueFunction',
16
+ * setValue: 'setValueFunction',
17
+ * onBlur: 'handleBlur',
18
+ * onClick: 'handleClick',
19
+ * onFocus: 'handleFocus',
20
+ * onKeyUp: 'handleKeyUp',
21
+ * onKeyDown: 'handleKeyDown',
22
+ * setErrorMessage: 'setErrorMessageFunction',
23
+ * setErrorState: 'setErrorStateFunction'
24
+ * };
25
+ * ```
26
+ * @interface
27
+ */
28
+ type TComponentPropsMapping = Partial<Record<TComponentPropsMappingSubset, string>> & {
29
+ getValue?: string;
30
+ setValue?: string;
31
+ setErrorMessage?: string;
32
+ setErrorState?: string;
33
+ };
34
+ /**
35
+ * @type TMapper
36
+ * Represents the mapping of a component, including the component type,
37
+ * name, events, and an optional function to handle value changes.
38
+ *
39
+ * @property {ElementType} component - The component that will represent the input.
40
+ * * @property {ElementType} asynccomponent - The component that will represent the input but dynamically imported (suspense/lazy).
41
+ * @property {string} componentName - The name of the component.
42
+ * @property {TComponentPropsMapping} [events] - Mapping event properties for the component.
43
+ * @property {TValueChangeEvent} [valueChangeEvent] - Optional function to handle value changes.
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * const mappers: TMapper<ElementType>[] = [
48
+ * {
49
+ * component: InputElement,
50
+ * componentName: 'input',
51
+ * events: {
52
+ * getValue: 'onChange2',
53
+ * onBlur: 'onBlur2',
54
+ * onFocus: 'onFocus2',
55
+ * }
56
+ * },
57
+ * {
58
+ * component: Container,
59
+ * componentName: 'row',
60
+ * },
61
+ * {
62
+ * component: Dropdown,
63
+ * componentName: 'dropdown',
64
+ * valueChangeEvent: (event: {
65
+ * id: string;
66
+ * label: string;
67
+ * value: string;
68
+ * }) => ({ _value: event.value, _stateValue: event.id }),
69
+ * },
70
+ * {
71
+ * component: DatePicker,
72
+ * componentName: 'datepicker',
73
+ * valueChangeEvent: (event: string) => event,
74
+ * },
75
+ * ];
76
+ * ```
77
+ * @interface
78
+ */
79
+ type TMapper<T> = {
80
+ componentName: string;
81
+ events?: TComponentPropsMapping;
82
+ valueChangeEvent?: TValueChangeEvent;
83
+ } & OneOf<{
84
+ component: T;
85
+ asynccomponent: T;
86
+ }>;
87
+ export { TMapper, TComponentPropsMapping };