@bolttech/form-engine-core 1.0.0-beta.15 → 1.0.0-beta.17

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.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Subject, Subscription, groupBy, mergeMap, debounceTime, filter, combineLatest, startWith, map, distinctUntilKeyChanged } from 'rxjs';
2
2
  import creditCardType from 'credit-card-type';
3
- import { isNumber as isNumber$1, isFunction, cloneDeep, merge, isEqual, get, isNil, set } from 'lodash';
3
+ import { isNumber as isNumber$1, isFunction, cloneDeep, isEqual, get, isNil, set } from 'lodash';
4
4
  import { getCurrencySymbol } from '@gaignoux/currency';
5
5
 
6
6
  var TMutationEnum;
@@ -48,8 +48,8 @@ const DEFAULT_API_DEBOUNCE_TIME = 1000;
48
48
  const DEFAULT_STATE_REFRESH_TIME = 100;
49
49
  const TEMPLATE_REGEX_STRING_CONCATENATION_DETECTOR = /^\$\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*\}$/;
50
50
  const TEMPLATE_REGEX_DELIMITATOR = /\$\{((?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*)\}/g;
51
- const TEMPLATE_REGEX_OPERATOR_SPLITTER = /\s*(\|\||&&|!)\s*/g;
52
- const TEMPLATE_REGEX_OPERATOR_MATCHER = /^\|\||&&|!$/;
51
+ const TEMPLATE_REGEX_OPERATOR_SPLITTER = /\s*(\|\||&&|!+)\s*/g;
52
+ const TEMPLATE_REGEX_OPERATOR_MATCHER = /^\|\||&&|!+$/;
53
53
  const TEMPLATE_AVALIABLE_SCOPES = ['fields', 'iVars', 'form'];
54
54
  const ALLOWED_RESET_PROPS_MUTATIONS = ['api', 'apiSchema', 'props', 'validations', 'visibilityConditions', 'resetValues'];
55
55
  const DEFAULT_LOG_VERBOSE = false;
@@ -578,7 +578,7 @@ const formatters = {
578
578
  * console.log(maskedValue); // Output: 'ab***gh###'
579
579
  * ```
580
580
  */
581
- var generic = ((value, masks) => {
581
+ var generic = (value, masks) => {
582
582
  if (!(masks === null || masks === void 0 ? void 0 : masks.generic)) return value;
583
583
  let masked = value;
584
584
  masks.generic.forEach(item => {
@@ -597,7 +597,7 @@ var generic = ((value, masks) => {
597
597
  masked = masked.slice(0, from - 1) + maskedPortion + masked.slice(to);
598
598
  });
599
599
  return masked;
600
- });
600
+ };
601
601
 
602
602
  /**
603
603
  * Replaces all characters in a string with a specified replacement string or character.
@@ -882,7 +882,7 @@ const masks = {
882
882
  * console.log(isValid); // Output: true or false based on validation
883
883
  * ```
884
884
  */
885
- var length = ((value, validations) => {
885
+ var length = (value, validations) => {
886
886
  if (!validations.length || !value) return false;
887
887
  let targetValue = value;
888
888
  // We want length even if it is a numeric
@@ -898,7 +898,7 @@ var length = ((value, validations) => {
898
898
  greaterOrEqual: targetValue.length < validations.length.target
899
899
  };
900
900
  return condition[validations.length.rule];
901
- });
901
+ };
902
902
 
903
903
  /**
904
904
  * Validates a Spanish NIF (Número de Identificación Fiscal).
@@ -1136,7 +1136,7 @@ const CIF = value => {
1136
1136
  * console.log(isValid); // Output: true or false based on validation
1137
1137
  * ```
1138
1138
  */
1139
- var document = ((value, validations) => {
1139
+ var document = (value, validations) => {
1140
1140
  if (!value || !validations.document) return true;
1141
1141
  const validation = {
1142
1142
  NIF: (value, locale) => NIF(value, locale),
@@ -1145,7 +1145,7 @@ var document = ((value, validations) => {
1145
1145
  IBAN: value => IBAN(value)
1146
1146
  };
1147
1147
  return validation[validations.document.type](value, validations.document.locale);
1148
- });
1148
+ };
1149
1149
 
1150
1150
  /**
1151
1151
  * Validates if a value exceeds the maximum allowed value.
@@ -2263,10 +2263,10 @@ function run$1(value, handlers, validations) {
2263
2263
  * const isValid = validateValue(value, methods);
2264
2264
  * console.log(isValid); // Output: true
2265
2265
  */
2266
- var namedRule = ((value, methods, validations) => {
2266
+ var namedRule = (value, methods, validations) => {
2267
2267
  if (!methods) return false;
2268
2268
  return run$1(value, methods, validations).some(validation => validation);
2269
- });
2269
+ };
2270
2270
 
2271
2271
  /**
2272
2272
  * @internal
@@ -2504,7 +2504,7 @@ class FormField {
2504
2504
  submitEvent,
2505
2505
  visibility
2506
2506
  }) {
2507
- var _a, _b, _c, _d, _e, _f, _g;
2507
+ var _a, _b, _c, _d, _e, _f;
2508
2508
  this.valueSubscription$ = new Subscription();
2509
2509
  this.fieldStateSubscription$ = new Subscription();
2510
2510
  this.formIndex = formIndex;
@@ -2520,7 +2520,6 @@ class FormField {
2520
2520
  this.path = path;
2521
2521
  this.children = children;
2522
2522
  this.validations = cloneDeep(schemaComponent.validations);
2523
- this.errorMessages = cloneDeep((_a = schemaComponent.validations) === null || _a === void 0 ? void 0 : _a.messages);
2524
2523
  this.visibilityConditions = cloneDeep(schemaComponent.visibilityConditions);
2525
2524
  this.resetValues = cloneDeep(schemaComponent.resetValues);
2526
2525
  this.resetPropertyValues = cloneDeep(schemaComponent.resetPropertyValues);
@@ -2528,7 +2527,7 @@ class FormField {
2528
2527
  this.formatters = cloneDeep(schemaComponent.formatters);
2529
2528
  this.masks = cloneDeep(schemaComponent.masks);
2530
2529
  if (mapper.valueChangeEvent) this.valueChangeEvent = mapper.valueChangeEvent;
2531
- if ((_b = mapper.events) === null || _b === void 0 ? void 0 : _b.setValue) this.valuePropName = mapper.events.setValue;
2530
+ if ((_a = mapper.events) === null || _a === void 0 ? void 0 : _a.setValue) this.valuePropName = mapper.events.setValue;
2532
2531
  this.mapper = mapper;
2533
2532
  this.validateVisibility = validateVisibility;
2534
2533
  this.resetValue = resetValue;
@@ -2547,10 +2546,10 @@ class FormField {
2547
2546
  this._visibility = typeof visibility === 'boolean' ? visibility : true;
2548
2547
  this._api = {
2549
2548
  default: {
2550
- response: ((_e = (_d = (_c = this.apiSchema) === null || _c === void 0 ? void 0 : _c.defaultConfig) === null || _d === void 0 ? void 0 : _d.config) === null || _e === void 0 ? void 0 : _e.fallbackValue) || '',
2549
+ response: ((_d = (_c = (_b = this.apiSchema) === null || _b === void 0 ? void 0 : _b.defaultConfig) === null || _c === void 0 ? void 0 : _c.config) === null || _d === void 0 ? void 0 : _d.fallbackValue) || '',
2551
2550
  status: null
2552
2551
  },
2553
- named: ((_f = this.apiSchema) === null || _f === void 0 ? void 0 : _f.configs) && Object.keys((_g = this.apiSchema) === null || _g === void 0 ? void 0 : _g.configs).reduce((acc, curr) => {
2552
+ named: ((_e = this.apiSchema) === null || _e === void 0 ? void 0 : _e.configs) && Object.keys((_f = this.apiSchema) === null || _f === void 0 ? void 0 : _f.configs).reduce((acc, curr) => {
2554
2553
  var _a, _b;
2555
2554
  acc[curr] = {
2556
2555
  response: ((_b = (_a = this.apiSchema) === null || _a === void 0 ? void 0 : _a.configs) === null || _b === void 0 ? void 0 : _b[curr].config.fallbackValue) || '',
@@ -2611,9 +2610,8 @@ class FormField {
2611
2610
  * @param {Record<string, unknown>} props - The new properties to be set.
2612
2611
  */
2613
2612
  set props(props) {
2614
- const diffProps = merge(cloneDeep(this.props), props);
2615
- if (typeof diffProps === 'undefined' || isEqual(diffProps, this.props)) return;
2616
- this._props = diffProps;
2613
+ if (typeof props === 'undefined' || isEqual(props, this.props)) return;
2614
+ this._props = props;
2617
2615
  this.propsSubject$.next(this.props);
2618
2616
  this.templateSubject$.next({
2619
2617
  scope: 'fields',
@@ -2632,6 +2630,7 @@ class FormField {
2632
2630
  return props.filter(el => typeof el === 'string' && el.includes('${') ? false : true).map(el => FormField.filterProps(el));
2633
2631
  }
2634
2632
  if (typeof props === 'object' && props !== null) {
2633
+ if (props instanceof Date) return props;
2635
2634
  return Object.keys(props).reduce((acc, curr) => {
2636
2635
  const propValue = props[curr];
2637
2636
  if (typeof propValue === 'string' && propValue.includes('${')) {
@@ -2947,16 +2946,17 @@ class FormField {
2947
2946
  const errors = {};
2948
2947
  const schemaValidations = (_a = this.validations) === null || _a === void 0 ? void 0 : _a.methods;
2949
2948
  schemaValidations && Object.keys(schemaValidations).forEach(validationKey => {
2949
+ var _a;
2950
2950
  const error = handleValidation(this.value, schemaValidations, validations, validationKey);
2951
2951
  // setting valid flag
2952
2952
  valid = !error && valid;
2953
2953
  // setting error messages
2954
- if (error && this.errorMessages) {
2955
- if (validationKey in this.errorMessages) {
2956
- const messages = this.errorMessages;
2954
+ if (error && ((_a = this.validations) === null || _a === void 0 ? void 0 : _a.messages)) {
2955
+ if (validationKey in this.validations.messages) {
2956
+ const messages = this.validations.messages;
2957
2957
  errors[validationKey] = messages[validationKey];
2958
- } else if ('default' in this.errorMessages) {
2959
- errors[validationKey] = this.errorMessages.default;
2958
+ } else if ('default' in this.validations.messages) {
2959
+ errors[validationKey] = this.validations.messages.default;
2960
2960
  }
2961
2961
  } else {
2962
2962
  delete errors[validationKey];
@@ -3822,7 +3822,7 @@ class FormCore {
3822
3822
  value
3823
3823
  }) {
3824
3824
  const field = this.fields.get(key);
3825
- if (!field || field.mounted) {
3825
+ if (!field) {
3826
3826
  this.queuedFieldResetPropertyEvents.set(key, {
3827
3827
  property,
3828
3828
  path,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bolttech/form-engine-core",
3
- "version": "1.0.0-beta.15",
3
+ "version": "1.0.0-beta.17",
4
4
  "module": "./index.esm.js",
5
5
  "type": "module",
6
6
  "main": "./index.esm.js",
@@ -22,7 +22,6 @@ declare class FormField {
22
22
  visibilityConditions?: TVisibility[];
23
23
  resetValues?: TResetValueMethods[];
24
24
  resetPropertyValues?: TResetPathMethods[];
25
- errorMessages?: TErrorMessages;
26
25
  apiSchema?: TApiEvent;
27
26
  formatters?: TFormatters;
28
27
  masks?: TMasks;