@bolttech/form-engine 0.14.3 → 3.0.0-beta.2

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 (79) hide show
  1. package/README.md +2 -1628
  2. package/index.esm.d.ts +1 -0
  3. package/index.esm.js +1683 -0
  4. package/package.json +15 -16
  5. package/src/components/AsFormField/AsFormField.d.ts +4 -0
  6. package/src/components/FieldWrapper/FieldWrapper.d.ts +4 -0
  7. package/src/components/Form/Form.d.ts +4 -0
  8. package/src/components/index.d.ts +2 -0
  9. package/src/context/FormGroupContext.d.ts +27 -0
  10. package/src/generators/formBuilder.d.ts +11 -0
  11. package/src/index.d.ts +3 -3
  12. package/src/types/index.d.ts +47 -0
  13. package/CHANGELOG.md +0 -529
  14. package/asFormField-3108e669.js +0 -2
  15. package/asFormField-3108e669.js.map +0 -1
  16. package/index.js +0 -2
  17. package/index.js.map +0 -1
  18. package/react.js +0 -2
  19. package/react.js.map +0 -1
  20. package/src/adapters/react/Field.d.ts +0 -4
  21. package/src/adapters/react/Form.d.ts +0 -5
  22. package/src/adapters/react/Submit.d.ts +0 -3
  23. package/src/adapters/react/asFormField.d.ts +0 -4
  24. package/src/adapters/react/context.d.ts +0 -5
  25. package/src/adapters/react/index.d.ts +0 -7
  26. package/src/adapters/react/types.d.ts +0 -326
  27. package/src/adapters/react/useForceUpdate.d.ts +0 -3
  28. package/src/adapters/react/useForm.d.ts +0 -12
  29. package/src/adapters/react/useFormGroup.d.ts +0 -3
  30. package/src/core/apis/formatters.d.ts +0 -16
  31. package/src/core/apis/index.d.ts +0 -4
  32. package/src/core/apis/masks.d.ts +0 -3
  33. package/src/core/apis/validations.d.ts +0 -11
  34. package/src/core/apis/varOps.d.ts +0 -4
  35. package/src/core/constants/events.d.ts +0 -32
  36. package/src/core/constants/index.d.ts +0 -5
  37. package/src/core/constants/observer.d.ts +0 -7
  38. package/src/core/events/ObserverError.d.ts +0 -7
  39. package/src/core/events/events.types.d.ts +0 -27
  40. package/src/core/events/index.d.ts +0 -2
  41. package/src/core/handlers/common/templating.d.ts +0 -2
  42. package/src/core/handlers/field/api.d.ts +0 -4
  43. package/src/core/handlers/field/blur.d.ts +0 -2
  44. package/src/core/handlers/field/change.d.ts +0 -2
  45. package/src/core/handlers/field/clearFields.d.ts +0 -4
  46. package/src/core/handlers/field/data.d.ts +0 -3
  47. package/src/core/handlers/field/filter.d.ts +0 -2
  48. package/src/core/handlers/field/focus.d.ts +0 -2
  49. package/src/core/handlers/field/formatters.d.ts +0 -4
  50. package/src/core/handlers/field/htmlEventParser.d.ts +0 -6
  51. package/src/core/handlers/field/keydown.d.ts +0 -2
  52. package/src/core/handlers/field/keyup.d.ts +0 -2
  53. package/src/core/handlers/field/masks.d.ts +0 -4
  54. package/src/core/handlers/field/mount.d.ts +0 -2
  55. package/src/core/handlers/field/validations.d.ts +0 -4
  56. package/src/core/handlers/field/visibilityConditions.d.ts +0 -4
  57. package/src/core/handlers/flows.d.ts +0 -47
  58. package/src/core/handlers/form/bindFields.d.ts +0 -3
  59. package/src/core/handlers/form/hooks.d.ts +0 -3
  60. package/src/core/handlers/form/steps.d.ts +0 -2
  61. package/src/core/handlers/form/templating.d.ts +0 -2
  62. package/src/core/handlers/form/validate.d.ts +0 -2
  63. package/src/core/handlers/form/visibilityConditions.d.ts +0 -4
  64. package/src/core/index.d.ts +0 -3
  65. package/src/core/managers/Base.d.ts +0 -19
  66. package/src/core/managers/Factory.d.ts +0 -52
  67. package/src/core/managers/Field.d.ts +0 -33
  68. package/src/core/managers/Form.d.ts +0 -28
  69. package/src/core/managers/Scope.d.ts +0 -12
  70. package/src/core/managers/index.d.ts +0 -1
  71. package/src/core/types/index.d.ts +0 -937
  72. package/src/core/utils/common.d.ts +0 -9
  73. package/src/core/utils/credit-card.d.ts +0 -16
  74. package/src/core/utils/index.d.ts +0 -6
  75. package/src/core/utils/object.d.ts +0 -27
  76. package/src/core/utils/string.d.ts +0 -3
  77. package/src/core/utils/value.d.ts +0 -2
  78. package/types.js +0 -2
  79. package/types.js.map +0 -1
@@ -1,937 +0,0 @@
1
- /// <reference types="react" />
2
- import { ICustomValidationValue } from '@core/apis/validations';
3
- import { EEVents } from '@core/constants';
4
- import { TEventInformation } from '@core/events';
5
- import Field from "@core/managers/Field";
6
- export declare type TObserverData<T> = {
7
- data: any;
8
- event: TEventsKeys;
9
- namespace: string;
10
- payload: T;
11
- };
12
- export declare type TObservable = (data: any, unsubscribe: () => void) => any;
13
- export declare type TEvents = Record<string, TObservable[]>;
14
- export interface IObservable {
15
- events: TEvents;
16
- }
17
- export declare type TScopeNamespaces = 'global' | 'api' | 'hooks' | 'fields' | 'configs';
18
- export declare type TSetGlobalScope = {
19
- namespace: TScopeNamespaces;
20
- key?: string;
21
- data: any;
22
- merge?: boolean;
23
- };
24
- export declare type TScope = {
25
- global?: any;
26
- api?: any;
27
- hooks?: any;
28
- configs?: TConfigs & {
29
- disable?: boolean;
30
- enableLogging?: boolean;
31
- };
32
- fields?: any;
33
- };
34
- export declare type TFactoryOptions = {
35
- schema?: TSchema;
36
- initialScope?: TScope;
37
- initialValues?: Record<string, any>;
38
- newInstance?: boolean;
39
- group?: string;
40
- };
41
- export declare type TMapper = Record<string, Record<string, unknown>>;
42
- export declare type TMaskGeneric = {
43
- to: number;
44
- from: number;
45
- mask: string;
46
- }[];
47
- declare type TCurrencyMask = {
48
- locale: string;
49
- currency: string;
50
- };
51
- export declare type TComponentMasks = {
52
- generic?: TMaskGeneric;
53
- cardNumber?: boolean;
54
- hideCardNumber?: boolean;
55
- cardMask?: boolean;
56
- cardDate?: boolean;
57
- currencyMask?: TCurrencyMask;
58
- feinMask?: boolean;
59
- replaceAll?: string | number;
60
- callback?(value: string | number): string | number;
61
- };
62
- declare type TFormMessages = Record<string, {
63
- name: string;
64
- value?: any;
65
- values?: string[];
66
- required?: boolean;
67
- }>;
68
- export declare type TChildrenOptions = {
69
- childrenScope?: string[];
70
- blurredChildren?: string[];
71
- changedChildren?: string[];
72
- scopeBlurredChildren?: boolean;
73
- scopeChangedChildren?: boolean;
74
- };
75
- export declare type TFieldData = Record<string, TField>;
76
- export declare type TFields = {
77
- [x in string]: Field;
78
- };
79
- export declare type TSubmitValueData = Record<string, {
80
- value?: unknown;
81
- props?: Record<string, unknown>;
82
- }>;
83
- export declare type TFormRefActions = {
84
- submit(): void;
85
- step(index: number | string): TFormValues;
86
- stepForward(index?: number | string): TFormValues;
87
- stepBack(index?: number | string): TFormValues;
88
- validateForm(opts?: TChildrenOptions): Promise<TFormValues>;
89
- bindFields(payload: TSubmitValueData): void;
90
- values(opts: Pick<TChildrenOptions, 'scopeBlurredChildren' | 'scopeChangedChildren' | 'childrenScope'>): TFormValues;
91
- };
92
- export declare type THookPayload = {
93
- setScope(data: TSetGlobalScope): void;
94
- };
95
- export declare type THooks = {
96
- preMount?: () => Record<string, unknown>;
97
- preUnmount?: () => Record<string, unknown>;
98
- preSubmit?: (formData: TFormValues) => Record<string, unknown>;
99
- posSubmit?: (formData: TFormValues) => Record<string, unknown>;
100
- };
101
- export declare type TIVars = Record<string, unknown>;
102
- export declare type TEventsKeys = keyof typeof EEVents;
103
- export declare enum TAvailableHooks {
104
- 'preMount' = "preMount",
105
- 'preUnmount' = "preUnmount",
106
- 'preSubmit' = "preSubmit",
107
- 'postSubmit' = "postSubmit"
108
- }
109
- export declare type TField = {
110
- value?: string | number | boolean;
111
- errors?: TErrors;
112
- visible?: boolean;
113
- failedErrorMessages?: string[];
114
- mask?: string;
115
- changed?: boolean;
116
- keyup?: boolean;
117
- keydown?: boolean;
118
- blured?: boolean;
119
- focused?: boolean;
120
- name: string;
121
- mounted: boolean;
122
- metadata?: any;
123
- ignore?: boolean;
124
- schemaLocation?: {
125
- step: number;
126
- depth: number;
127
- index: number;
128
- };
129
- };
130
- declare type TPathError = Omit<TSchemaValidation, 'path'> & {
131
- path?: string;
132
- paths?: string[];
133
- preventUnMountValidation?: boolean;
134
- };
135
- export declare type TValidationDateFormats = 'MMDDYYYY' | 'DDMMYYYY' | 'YYYYMMDD' | 'YYYYDDMM' | 'timestamp';
136
- export declare type TValidationDateOperators = '<' | '>' | '===' | '>=' | '<=' | '!==' | '!!origin';
137
- export declare type TVAvailableValidationConditionsSet = {
138
- forceDefinedOrigin?: boolean;
139
- forceDefinedTarget?: boolean;
140
- origin?: string | number | boolean;
141
- condition: TValidationDateOperators;
142
- target?: string | number | boolean;
143
- };
144
- export declare type TVAvailableValidationConditions = {
145
- rule: 'and' | 'or';
146
- set: TVAvailableValidationConditionsSet[];
147
- conditions?: TVAvailableValidationConditions;
148
- };
149
- export declare type TVAvailableValidationMultipleValidations = {
150
- rule: 'AND' | 'OR' | 'NOT';
151
- validations: TVAvailableValidations;
152
- };
153
- export declare type TVAvailableValidations = {
154
- /**
155
- * The bool function is a validation function that checks if a given value indicating whether the validation has failed or not.
156
- *
157
- * @example - in a test environment
158
- * ```
159
- * const result = bool({
160
- * validationValue: false,
161
- * });
162
- * console.log(result); // { fail: false }
163
- * ```
164
- *
165
- * @example - real json usage with field value
166
- * ```
167
- * {
168
- * validations: {
169
- * bool: '${fields.input.value}'
170
- * },
171
- * },
172
- * ```
173
- *
174
- * @example - real json usage with iVar value
175
- * ```
176
- * {
177
- * validations: {
178
- * bool: '${global.validation}'
179
- * },
180
- * },
181
- * ```
182
- */
183
- bool?: string | boolean;
184
- /**
185
- * Validation based on conditions
186
- *
187
- * @example - Compare own field to two. Origin and target default to field value
188
- * ```
189
- * conditions: {
190
- * rule: 'and',
191
- * set: [
192
- * {
193
- * condition: '===',
194
- * target: '2',
195
- * },
196
- * {
197
- * origin: '2',
198
- * condition: '===',
199
- * },
200
- * ],
201
- * },
202
- * ```
203
- * @example - Binded to Postcode field value. Must be greater than or equal two
204
- * ```
205
- * conditions: {
206
- * rule: 'or',
207
- * set: [
208
- * {
209
- * origin: '${fields.postcode.value}',
210
- * condition: '>',
211
- * target: '2',
212
- * },
213
- * {
214
- * origin: '${fields.postcode.value}',
215
- * condition: '===',
216
- * target: '2',
217
- * },
218
- * ],
219
- * },
220
- * ```
221
- * @example - Binded to Postcode field value. Must be equal to two
222
- * ```
223
- * conditions: {
224
- * rule: 'or',
225
- * set: [
226
- * {
227
- * origin: '${fields.postcode.value}',
228
- * condition: '===',
229
- * target: '2',
230
- * },
231
- * ],
232
- * },
233
- * ```
234
- */
235
- conditions?: TVAvailableValidationConditions;
236
- /**
237
- * Applies multiple validations on the given value based on the specified truth table rule.
238
- *
239
- * @param {Object} TVAvailableValidationMultipleValidations - The multiple validations object param.
240
- * @param {'AND' | 'OR' | 'NOT'} TVAvailableValidationMultipleValidations.rule - The rule to be applied based of truth table ('AND', 'OR', or 'NOT').
241
- * @param {Object} TVAvailableValidationMultipleValidations.validations - Object containing validation rules.
242
- *
243
- * @example - Validating with the expression AND where current field must have a value of 'yes' and input 2 must have a value of 'no'
244
- * ```
245
- * multipleValidations: {
246
- * rule: 'AND',
247
- * validations: {
248
- * value: 'yes',
249
- * conditions: {
250
- * rule: 'and',
251
- * set: [
252
- * {
253
- * origin: '${fields.input2.value}',
254
- * condition: '===',
255
- * target: 'no'
256
- * },
257
- * ],
258
- * },
259
- * },
260
- * },
261
- * ```
262
- * @example - Validating with the expression OR where current field must have a value of '1995-12-12' or be a valid date with regex
263
- * ```
264
- * multipleValidations: {
265
- * rule: 'OR',
266
- * validations: {
267
- * value: '1995-12-12',
268
- * regex: '^\d{4}-\d{2}-\d{2}$',
269
- * },
270
- * },
271
- * ```
272
- * @example - Validating with the expression NOT where current field doesn't have a value of '1995-12-12' and not be a valid date with regex
273
- * ```
274
- * multipleValidations: {
275
- * rule: 'NOT',
276
- * validations: {
277
- * value: '1995-12-12',
278
- * regex: '^\d{4}-\d{2}-\d{2}$',
279
- * },
280
- * },
281
- * ```
282
- */
283
- multipleValidations?: TVAvailableValidationMultipleValidations;
284
- /**
285
- * Between validations
286
- *
287
- * @example - Between ages
288
- * ``` type teste = Pick<TVAvailableValidations, 'date'>
289
- * between: {
290
- * dates: [
291
- * {
292
- * operator: '>=',
293
- * origin: {
294
- * format: 'YYYYMMDD',
295
- * intervals: {
296
- * years: 18,
297
- * },
298
- * },
299
- * },
300
- * {
301
- * operator: '<=',
302
- * origin: {
303
- * format: 'YYYYMMDD',
304
- * intervals: {
305
- * years: 75,
306
- * },
307
- * },
308
- * }
309
- * ]
310
- * }
311
- * ```
312
- *
313
- * @example - Between numbers
314
- * ```
315
- * between: {
316
- * start: '3',
317
- * end: '4',
318
- * isIncludedBoundaries: true
319
- * },
320
- * ```
321
- *
322
- */
323
- between?: {
324
- /**
325
- * Array of date validations. To make it possible, ensure that the conditions is > and < in both date validations.
326
- */
327
- dates?: TVAvailableValidations['date'][];
328
- /**
329
- * The first number of the validation. If the current value is grater than this number, the validation will pass.
330
- */
331
- start?: number;
332
- /**
333
- * The second number of the validation. If the current value is lower than this number, the validation will pass.
334
- */
335
- end?: number;
336
- /**
337
- * If it's true, the comparision is transformed to >= and <=. So, the numbers that were passed are included in the validation.
338
- */
339
- isIncludedBoundaries?: boolean;
340
- };
341
- /**
342
- * Dates validations
343
- *
344
- * @example - Dates should be different
345
- * ```
346
- * date: {
347
- * operator: '!==',
348
- * origin: {
349
- * format: 'DDMMYYYY',
350
- * },
351
- * target: {
352
- * format: 'DDMMYYYY',
353
- * value: '10/10/2001',
354
- * },
355
- * },*
356
- * ```
357
- *
358
- * @example - Compare only valid dates using intervals
359
- * ```
360
- * date: {
361
- * onlyValidDate: true,
362
- * operator: '<',
363
- * origin: {
364
- * format: 'DD/MM/YYYY',
365
- * intervals: {
366
- * years: 1,
367
- * },
368
- * },
369
- * },
370
- * ```
371
- *
372
- * @example - Should have at max 85 years
373
- * ```
374
- * {
375
- * operator: '>',
376
- * origin: {
377
- * format: 'DDMMYYYY',
378
- * value: eightyFiveYearsDate,
379
- * intervals: {
380
- * years: 85,
381
- * },
382
- * },
383
- * }
384
- * }
385
- *
386
- * ```
387
- */
388
- date?: {
389
- /**
390
- * Flag to force only valid dates. Valid dates must be of min length of 8
391
- */
392
- onlyValidDate?: boolean;
393
- /**
394
- * List of operations you can do
395
- * - between origin and target dates
396
- * - between origin and intervals
397
- */
398
- operator: TValidationDateOperators;
399
- /**
400
- * The origin configurations
401
- */
402
- origin: {
403
- /**
404
- * Origin date value
405
- */
406
- value?: string | number;
407
- /**
408
- * The available date formats
409
- */
410
- format: TValidationDateFormats;
411
- /**
412
- * Intervals to compare with the original date.
413
- *
414
- * It will use todays date for comparison.
415
- *
416
- * @example
417
- *
418
- * origin date = 10/10/2022
419
- * interval.year = 1
420
- * operator = '==='
421
- *
422
- * It will compare (10/10/2022 + 1) with the current date and check if they are the same
423
- */
424
- intervals?: {
425
- years?: number;
426
- months?: number;
427
- days?: number;
428
- };
429
- };
430
- target?: {
431
- value: string | number;
432
- format: TValidationDateFormats;
433
- };
434
- };
435
- /**
436
- * Allow to validate if the input string is a valid date format
437
- */
438
- validDate?: TValidationDateFormats;
439
- /**
440
- * Allow to define a maximum length for the input to have no error
441
- */
442
- length?: number;
443
- /**
444
- * Will look into the input length and send an error if is not greater than this value
445
- */
446
- greaterThan?: number | string;
447
- /**
448
- * Specifies a regular expression pattern that the value should match.
449
- */
450
- regex?: string;
451
- /**
452
- * Specifies the maximum length of the value (if it's a string).
453
- */
454
- maxLength?: number;
455
- /**
456
- * Specifies the minimum length of the value (if it's a string).
457
- */
458
- minLength?: number;
459
- /**
460
- * Specifies whether the field is required.
461
- */
462
- required?: boolean;
463
- /**
464
- * Specifies that the value should contain only letters.
465
- */
466
- onlyLetters?: boolean;
467
- /**
468
- * Specifies a value that the field should match.
469
- */
470
- value?: string | number | boolean;
471
- /**
472
- * Specifies that the field should not be empty.
473
- */
474
- notEmpty?: boolean;
475
- /**
476
- * A callback function that performs custom validation on the value.
477
- * @param value - The value to be validated.
478
- * @returns An object with validation results.
479
- */
480
- callback?(value: string | number): {
481
- fail: boolean;
482
- errorMessage?: string;
483
- };
484
- /**
485
- * Specifies a numeric range for the value.
486
- */
487
- numericRange?: {
488
- start: number | string;
489
- end: number | string;
490
- };
491
- /**
492
- * Specifies whether the value should be a number.
493
- */
494
- isNumber?: boolean;
495
- /**
496
- * Specifies that the field should not have extra spaces.
497
- */
498
- hasNoExtraSpaces?: boolean;
499
- /**
500
- * Specifies that the value should be an email address.
501
- */
502
- email?: boolean;
503
- /**
504
- * Specifies that the value should be less than a given number or string.
505
- */
506
- lessThan?: number | string;
507
- /**
508
- * Specifies that the value should be a sequential number.
509
- */
510
- sequentialNumber?: boolean;
511
- /**
512
- * Specifies that the value should not contain repeated numbers.
513
- */
514
- repeatedNumbers?: boolean;
515
- /**
516
- * Specifies that the value should be a URL.
517
- */
518
- url?: boolean;
519
- /**
520
- * Specifies a path error type.
521
- */
522
- path?: TPathError;
523
- /**
524
- * Specifies that the value should be a valid credit card number.
525
- */
526
- isCreditCard?: string[];
527
- /**
528
- * Specifies that the value should be a valid credit card number with a specific length.
529
- */
530
- isCreditCardAndLength?: string[];
531
- /**
532
- * Specifies that the value should match a credit card code with available options.
533
- */
534
- isCreditCodeMatch?: {
535
- numberCard: string;
536
- availableOptions: string[];
537
- };
538
- /**
539
- * Specifies custom validation options for the field.
540
- */
541
- customValidation?: ICustomValidationValue[];
542
- /**
543
- * Specifies that spaces are not allowed in the field.
544
- */
545
- notAllowSpaces?: true;
546
- /**
547
- * Specifies that the value should be in a predefined list of values.
548
- */
549
- isInTheList?: string[] | number[] | string;
550
- /**
551
- * Specifies field validation rules for nested fields.
552
- */
553
- fields?: {
554
- /**
555
- * The rule for validating nested fields (e.g., 'every').
556
- */
557
- rule: 'every';
558
- /**
559
- * An array of nested field validation configurations.
560
- */
561
- set: {
562
- /**
563
- * The binding for the nested field.
564
- */
565
- bind: string;
566
- /**
567
- * The field name for the nested field.
568
- */
569
- fieldName: string;
570
- /**
571
- * Validation options for the nested field, excluding the 'fields' property.
572
- */
573
- validations: Omit<TVAvailableValidations, 'fields'>;
574
- }[];
575
- };
576
- /**
577
- * Specifies that the value should be existed.
578
- */
579
- exists?: string | number;
580
- };
581
- export declare type TGenericValidationRule = {
582
- [key: string]: TVAvailableValidations;
583
- };
584
- export declare type TSchemaValidation = TVAvailableValidations | TGenericValidationRule;
585
- export declare type TStepData = {
586
- navigated: boolean;
587
- index: number;
588
- data: Record<number, Pick<TFormValues, 'fields' | 'erroredFields' | 'formatted' | 'filteredFields'>>;
589
- currentStepSchema?: TComponent;
590
- isValid: boolean;
591
- numSteps?: number;
592
- };
593
- export declare type TFormValues = {
594
- predictableErroredFields: string[];
595
- erroredFields: string[];
596
- fields: TFieldData;
597
- formatted: Record<string, unknown>;
598
- filteredFields?: Record<string, unknown>;
599
- form: {
600
- steps: TStepData;
601
- isValid: boolean;
602
- messages: string[];
603
- scope: TScope;
604
- };
605
- };
606
- export declare type TError = {
607
- value: unknown;
608
- message?: string;
609
- fail: boolean;
610
- };
611
- export declare type TErrors = Record<string, TError> | undefined;
612
- export declare type TErrorMessages = Record<string, string>;
613
- export declare type TSchemaValidations = TSchemaHandler<TSchemaValidation>;
614
- declare type TFormLevelSchemaHandler<T> = Partial<Record<EEVents.AFTER_FIELD_API_CALL | EEVents.ON_FIELD_CHANGE | EEVents.ON_FIELD_KEYUP | EEVents.ON_FIELD_KEYDOWN | EEVents.ON_FORM_REHYDRATE | EEVents.ON_FORM_MOUNT | EEVents.ON_SCOPE_CHANGE, T>>;
615
- declare type TSchemaHandler<T> = Partial<Record<EEVents.AFTER_FIELD_API_CALL | EEVents.ON_FIELD_REHYDRATE | EEVents.ON_FIELD_CLEARED | EEVents.ON_FIELD_BINDED | EEVents.ON_FIELD_CHANGE | EEVents.ON_FIELD_KEYUP | EEVents.ON_FIELD_KEYDOWN | EEVents.ON_FIELD_BLUR | EEVents.ON_FIELD_MOUNT | EEVents.ON_FIELD_FOCUS | EEVents.ON_FIELD_CLICK, T>>;
616
- export declare type TSchemaVisibilityConditions = {
617
- /**
618
- * Enables visibility of fields only if any or all validation conditions are positive.
619
- *
620
- * The default is false, so if all validations are false, the field will display, if any are positive,
621
- * the field will hide, as well as if all are positive.
622
- */
623
- showOnlyIfTrue?: boolean;
624
- /**
625
- * Allows you to choose the type of chain for validations.
626
- *
627
- * The default is OR, where at least one validation needs to be true to work. In the case of AND,
628
- * all validations must be true.
629
- */
630
- rule?: 'or' | 'and';
631
- /**
632
- * The validations that will say if the target field will be visible or not
633
- *
634
- * Those validations will run against your field (the one that has this directive)
635
- */
636
- validations: TSchemaValidation;
637
- /**
638
- * Target field that will have the visibility toggled
639
- */
640
- fieldName?: string;
641
- /**
642
- * Target fields that will have the visibility toggled
643
- */
644
- fieldNames?: string[];
645
- }[];
646
- export declare type TClearFieldValue = string | number | boolean;
647
- export declare type TClearField = {
648
- /**
649
- * The clearValues runs validations on the target field and not on the field it is declaring.
650
- * Therefore, set this prop with true if you want validations to be performed on the current field.
651
- */
652
- useCurrentFieldValidation?: boolean;
653
- /**
654
- * Validations to run for the target field
655
- */
656
- validations?: TSchemaValidation | TSchemaValidation[];
657
- /**
658
- * target fields that will be used in the validation specified
659
- */
660
- fields: string[];
661
- /**
662
- * The cleared values on the fields in case they do not pass the validation
663
- */
664
- clearedValue: TClearFieldValue | TClearFieldValue[];
665
- /**
666
- * The cleared props from each component field on target fields array
667
- */
668
- clearedProps?: Record<string, unknown> | Record<string, unknown>[];
669
- /**
670
- * The cleared values on the fields in case they do pass the validation
671
- */
672
- defaultClearedValue?: TClearFieldValue | TClearFieldValue[];
673
- /**
674
- * The cleared props from each component field on target fields array if they pass validation
675
- */
676
- defaultClearedProps?: Record<string, unknown> | Record<string, unknown>[];
677
- };
678
- export declare type TSchemaClearFields = TClearField[];
679
- export declare type TSchemaApi = {
680
- /**
681
- * Specify a debounce time in miliseconds for your call
682
- */
683
- debounceTime?: number;
684
- method: 'GET' | 'POST' | 'PUT' | 'PATCH';
685
- url: string;
686
- headers?: HeadersInit | undefined;
687
- body?: Record<string, any>;
688
- fieldValueAsParams?: Record<string, string>;
689
- fieldValueAsPathParams?: string[];
690
- scope?: string;
691
- blockRequestWhenInvalid?: boolean;
692
- preConditions?: TSchemaValidation;
693
- }[];
694
- export declare type TSchemaMasks = {
695
- cleanMask?: boolean;
696
- } & TComponentMasks;
697
- export declare type TFormEventDirectives = {
698
- visibilityConditions: TSchemaVisibilityConditions;
699
- };
700
- export declare type TComponent = {
701
- /**
702
- * This name will be used later to correlate the field with the value, and you will be able to read it.
703
- *
704
- * You can also mount here complex objects like
705
- *
706
- * name={a.b.c}
707
- *
708
- * that will result in
709
- * a: {
710
- * b: {
711
- * c: 'field_value'
712
- * }
713
- * }
714
- */
715
- name: string;
716
- /**
717
- * A component name that should map to the one you gave in the form mappings
718
- *
719
- * @example - For React
720
- * ```
721
- * const mappings: TMapper = {
722
- * input: { component: Input },
723
- * formGroup: { component: FormGroup },
724
- * };
725
- * ```
726
- *
727
- * The component name for the Input element will be "input" ending up like
728
- * ```
729
- * {
730
- * component: 'input'
731
- * }
732
- * ```
733
- */
734
- component: string;
735
- /**
736
- * You can attach metadata to your component that will be forwarded to you after on your frontend
737
- * callback methods link `onData`, `onBlur` etc
738
- */
739
- metadata?: Record<string, any>;
740
- /**
741
- * This property allows you to specify a virtual fieldName that can be in several fields
742
- *
743
- * USAGE - You have two fields but you want to have the value stored only under one name
744
- *
745
- */
746
- group?: string;
747
- wrapper?: new () => React.Component;
748
- children?: TComponent[];
749
- /**
750
- * Field error messages in case any validation fails
751
- *
752
- * @example - Set a default error message for all the validations
753
- *
754
- * ```
755
- * {
756
- * errorMessages: {
757
- * default: 'default error message'
758
- * }
759
- * }
760
- * ```
761
- *
762
- * @example - Set error message for a given validation
763
- *
764
- * ```
765
- * {
766
- * validations: {
767
- * ON_FIELD_CHANGE: {
768
- * required: true
769
- * }
770
- * },
771
- * errorMessages: {
772
- * required: 'This field is required'
773
- * }
774
- * }
775
- * ```
776
- *
777
- */
778
- errorMessages?: TErrorMessages;
779
- type?: 'text' | 'number' | string;
780
- /**
781
- * Allow you to set a initial state for this field
782
- */
783
- state?: {
784
- /**
785
- * Hide the field
786
- */
787
- hidden?: boolean;
788
- /**
789
- * Ignore value from field
790
- */
791
- ignoreValue?: boolean;
792
- };
793
- /**
794
- * This key lets you inject props directly into the component
795
- */
796
- props?: Record<string, unknown>;
797
- /**
798
- * Setup validations to be used in the field.
799
- *
800
- * You can setup validations in several life-cycle methods
801
- *
802
- * @example - Required validation
803
- * ```
804
- * validations: {
805
- ON_FIELD_CHANGE: {
806
- required: true,
807
- },
808
- },
809
- * ```
810
- */
811
- validations?: TSchemaHandler<Pick<TEventReducedSchema, 'validations'>['validations']>;
812
- /**
813
- * Filters the component value based on a validation.
814
- */
815
- filter?: Pick<TEventReducedSchema, 'validations'>['validations'];
816
- /**
817
- * Allows you to specify the conditions a given field will be visible
818
- * what will run when this field meets the specified life-cycle
819
- */
820
- visibilityConditions?: Omit<TSchemaHandler<Pick<TEventReducedSchema, 'visibilityConditions'>['visibilityConditions']>, 'ON_FIELD_REHYDRATE' | 'ON_FIELD_CLEARED' | 'ON_FIELD_FOCUS'>;
821
- /**
822
- * Will clear target fields in case they do not pass with the specified validations
823
- */
824
- clearFields?: Omit<TSchemaHandler<Pick<TEventReducedSchema, 'clearFields'>['clearFields']>, 'ON_FIELD_REHYDRATE' | 'ON_FIELD_CLEARED' | 'ON_FIELD_FOCUS'>;
825
- /**
826
- * Allows you to make api calls using events emitted by the component.
827
- */
828
- api?: Omit<TSchemaHandler<Pick<TEventReducedSchema, 'api'>['api']>, 'ON_FIELD_REHYDRATE' | 'ON_FIELD_FOCUS' | 'AFTER_FIELD_API_CALL'>;
829
- /**
830
- * Allows you to display the value of the masked component by events
831
- */
832
- masks?: Partial<Record<EEVents.ON_FIELD_BLUR | EEVents.ON_FIELD_MOUNT | EEVents.ON_FIELD_FOCUS | EEVents.ON_FIELD_CHANGE | EEVents.ON_FIELD_KEYUP | EEVents.ON_FIELD_KEYDOWN, Pick<TEventReducedSchema, 'masks'>['masks']>>;
833
- /**
834
- * Allows you to format the value that the field will receive for each event issuance
835
- */
836
- formatters?: Omit<TSchemaHandler<Pick<TEventReducedSchema, 'formatters'>['formatters']>, 'ON_FIELD_REHYDRATE' | 'ON_FIELD_FOCUS'>;
837
- };
838
- export declare type TEventReducedSchema = {
839
- api: TSchemaApi;
840
- clearFields: TSchemaClearFields;
841
- formatters: TSchemaFormatters;
842
- masks: TSchemaMasks;
843
- validations: TSchemaValidation;
844
- visibilityConditions: TSchemaVisibilityConditions;
845
- };
846
- export declare type TStep = {
847
- component: string;
848
- name: string;
849
- children: TComponent[];
850
- props?: Record<string, string>;
851
- };
852
- export declare type TComponentPropsMapping = {
853
- getValue?: string;
854
- setValue?: string;
855
- onBlur?: string;
856
- onClick?: string;
857
- onFocus?: string;
858
- onKeyUp?: string;
859
- onKeyDown?: string;
860
- setErrorMessage?: string;
861
- setErrorState?: string;
862
- };
863
- export declare type TPropsMapping = Record<string, TComponentPropsMapping>;
864
- export declare type TSchema = {
865
- /**
866
- * Used to disable form submit input and prevent to submit form using enter event.
867
- * Default is false.
868
- */
869
- disableFormSubmit?: boolean;
870
- action?: string;
871
- method?: string;
872
- /**
873
- * Give some configurations to the form
874
- */
875
- configs?: TConfigs;
876
- /**
877
- * Allows you to expose some messages to the outside world when something happen
878
- */
879
- messages?: TFormMessages;
880
- /**
881
- * Specify some static field defaults before rendereing the form.
882
- *
883
- * If you have initialValues in the frontend setted, those will ovewride this
884
- */
885
- formattedDataDefaults?: Record<string, unknown>;
886
- /**
887
- * Form level props mapping
888
- */
889
- propsMapping?: TPropsMapping;
890
- visibilityConditions?: TFormLevelSchemaHandler<TSchemaVisibilityConditions>;
891
- /**
892
- * Entry point for the form should be a step (even if you have only one)
893
- */
894
- components: TStep[];
895
- /**
896
- * You can have many fields in the form, but be interested only in some
897
- *
898
- * You can put here the fields you want to read onSubmit for example
899
- *
900
- * You will receive those in TFormValues.filteredFields
901
- */
902
- filteredFields?: string[];
903
- /**
904
- * Schema level iVars.
905
- *
906
- * These iVars will go to the global scope namespace
907
- */
908
- iVars?: TIVars;
909
- };
910
- export declare type TSplitterFormatterValue = {
911
- value: string;
912
- position: number;
913
- }[];
914
- export declare type TSchemaFormatters = {
915
- splitter?: TSplitterFormatterValue;
916
- capitalize?: boolean;
917
- upperCase?: boolean;
918
- gapsCreditCard?: string[];
919
- onlyNumbers?: boolean;
920
- onlyLetters?: boolean;
921
- regex?: string;
922
- callback?(value: string | number): string | number;
923
- };
924
- export declare type TConfigs = {
925
- observables?: {
926
- templates?: {
927
- exclude?: string[];
928
- };
929
- };
930
- };
931
- export declare type TFlowType = {
932
- [x: string]: {
933
- events: (component?: TComponent) => EEVents[];
934
- handler: (args: TEventInformation<unknown>) => void;
935
- }[];
936
- };
937
- export {};