myrta-ui 1.1.26 → 1.1.28

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.
@@ -4265,7 +4265,7 @@ const getErrorMessageHelper = (key, invalidMessages, messages, params) => {
4265
4265
 
4266
4266
  const requiredValidation = (value, validations, key, invalidMessages) => {
4267
4267
  const result = { isValid: true, message: null };
4268
- if (Array.isArray(value) && validations.type !== 'single') {
4268
+ if (Array.isArray(value) && validations.type !== 'single' && validations[key]) {
4269
4269
  value.forEach((field, idx) => {
4270
4270
  if ((field === '' || field === null || field === undefined)) {
4271
4271
  result.message = getErrorMessageHelper(key, invalidMessages, validations.messages);
@@ -4273,11 +4273,11 @@ const requiredValidation = (value, validations, key, invalidMessages) => {
4273
4273
  }
4274
4274
  });
4275
4275
  }
4276
- else if (Array.isArray(value) && validations.type === 'single' && value.length === 0) {
4276
+ else if (Array.isArray(value) && validations.type === 'single' && value.length === 0 && validations[key]) {
4277
4277
  result.message = getErrorMessageHelper(key, invalidMessages, validations.messages);
4278
4278
  result.isValid = false;
4279
4279
  }
4280
- else if (String(value) === '' || String(value) === 'false' || value === null || value === undefined || String(value) === '<p><br></p>') {
4280
+ else if ((String(value) === '' || String(value) === 'false' || value === null || value === undefined || String(value) === '<p><br></p>') && validations[key]) {
4281
4281
  result.message = getErrorMessageHelper(key, invalidMessages, validations.messages);
4282
4282
  result.isValid = false;
4283
4283
  }
@@ -17387,8 +17387,13 @@ class FormulaEditorComponent {
17387
17387
  endOffset: 0
17388
17388
  };
17389
17389
  this.searchText = '';
17390
- this.operatorList = ['+', '-', '*', '/'];
17391
- this.bracketList = ['(', ')'];
17390
+ this._operatorList = ['+', '-', '*', '/'];
17391
+ this._bracketList = ['(', ')'];
17392
+ this._itemList = [];
17393
+ this._modifiedItemList = {
17394
+ items: {},
17395
+ regExp: new RegExp(''),
17396
+ };
17392
17397
  this.value = '';
17393
17398
  this.visibleValue = '';
17394
17399
  this.isFocused = false;
@@ -17399,8 +17404,6 @@ class FormulaEditorComponent {
17399
17404
  // SAVE STATE
17400
17405
  this.uuid = v4();
17401
17406
  this.fields = [];
17402
- // TODO items
17403
- this.items = [];
17404
17407
  this.disabled = false;
17405
17408
  this.readonly = false;
17406
17409
  this.placeholder = '';
@@ -17417,11 +17420,17 @@ class FormulaEditorComponent {
17417
17420
  this.onTouched = () => {
17418
17421
  };
17419
17422
  }
17423
+ set items(items) {
17424
+ const itemsMap = Object.fromEntries(items.map(obj => [obj.label, obj.sysName]));
17425
+ this._itemList = items;
17426
+ this._modifiedItemList.items = itemsMap;
17427
+ this._modifiedItemList.regExp = new RegExp(items.map(s => s.label).join('|'), 'g');
17428
+ }
17420
17429
  get getErrorMessage() {
17421
17430
  return this.invalidMessage || ErrorMessagesEnum[this.errorModel.errorType];
17422
17431
  }
17423
17432
  get filteredList() {
17424
- return this.items.filter(item => item.label.includes(this.searchText));
17433
+ return this._itemList.filter(item => item.label.includes(this.searchText));
17425
17434
  }
17426
17435
  get getInvalid() {
17427
17436
  return this.errorModel.isError || this.invalid;
@@ -17440,14 +17449,15 @@ class FormulaEditorComponent {
17440
17449
  }
17441
17450
  writeValue(outsideValue) {
17442
17451
  if (outsideValue !== null) {
17452
+ const { visibleValue } = this._transformValue(this._modifiedValue(outsideValue));
17443
17453
  this.value = outsideValue;
17444
- this.visibleValue = this._transformValue(this._modifiedValue(outsideValue)).visibleValue;
17454
+ this.visibleValue = visibleValue;
17445
17455
  this._detector.detectChanges();
17446
17456
  }
17447
17457
  }
17448
17458
  onInput(event) {
17449
- const { value, searchText } = this._transformValue(this._inputValue, false);
17450
- this.updateValue(value);
17459
+ const { searchText } = this._transformValue(this._modifiedValue(this._inputValue), false);
17460
+ // this.updateValue(value);
17451
17461
  this.searchText = searchText;
17452
17462
  this._storeCursorPosition();
17453
17463
  }
@@ -17461,9 +17471,9 @@ class FormulaEditorComponent {
17461
17471
  }
17462
17472
  insertTag(whiteListItem) {
17463
17473
  this._restoreCursorPosition(this.inputElement.nativeElement);
17464
- this._insertPositionText(whiteListItem.label);
17474
+ this._insertPositionText(`{${whiteListItem.sysName}}`);
17465
17475
  setTimeout(() => {
17466
- const { value, visibleValue } = this._transformValue(this._inputValue, false);
17476
+ const { value, visibleValue } = this._transformValue(this._modifiedValue(this._inputValue), false);
17467
17477
  this.updateValue(value);
17468
17478
  this.updateVisibleValue(visibleValue);
17469
17479
  });
@@ -17483,30 +17493,26 @@ class FormulaEditorComponent {
17483
17493
  this.onTouched();
17484
17494
  }
17485
17495
  _modifiedValue(value) {
17486
- const clearedValue = value.trim().split(' ').filter(e => e !== '');
17487
- return clearedValue.map(v => {
17488
- const findItem = this.items.find(w => `{${w.sysName}}` === v);
17489
- return findItem ? findItem.label : v;
17490
- }).join(' ');
17496
+ return value.replace(this._modifiedItemList.regExp, match => `{${this._modifiedItemList.items[match]}}`);
17491
17497
  }
17492
17498
  _transformValue(content, analise = false) {
17493
- const valueArray = content.split(/[\s\u00A0]+/).filter(e => e !== '');
17499
+ const valueArray = content.split(/[\s\u00A0]+/).filter(Boolean);
17494
17500
  const visibleValueArray = [];
17495
17501
  const originalValueArray = [];
17496
17502
  let isInterpretationError = false;
17497
17503
  let searchText = '';
17498
17504
  valueArray.forEach((item) => {
17499
17505
  const clearedItem = item.trim();
17500
- const findItem = this.items.find(v => clearedItem.includes(v.label));
17506
+ const findItem = this._itemList.find(v => clearedItem.includes(v.sysName));
17501
17507
  if (findItem) {
17502
17508
  visibleValueArray.push(createTag(findItem.label));
17503
17509
  originalValueArray.push(createTagOutside(findItem.sysName));
17504
17510
  }
17505
- else if (this.bracketList.find(v => v === clearedItem)) {
17511
+ else if (this._bracketList.find(v => v === clearedItem)) {
17506
17512
  visibleValueArray.push(createBracket(clearedItem));
17507
17513
  originalValueArray.push(clearedItem);
17508
17514
  }
17509
- else if (this.operatorList.find(v => v === clearedItem)) {
17515
+ else if (this._operatorList.find(v => v === clearedItem)) {
17510
17516
  visibleValueArray.push(createOperator(clearedItem));
17511
17517
  originalValueArray.push(clearedItem);
17512
17518
  }
@@ -17533,8 +17539,8 @@ class FormulaEditorComponent {
17533
17539
  _checkErrors(valueArray, isInterpretationError) {
17534
17540
  this._disableError();
17535
17541
  this._toggleError(checkBracketErrors(valueArray));
17536
- this._toggleError(checkDividerErrors(valueArray, this.items));
17537
- this._toggleError(checkSequenceErrors(valueArray, this.operatorList, this.bracketList));
17542
+ this._toggleError(checkDividerErrors(valueArray, this._itemList));
17543
+ this._toggleError(checkSequenceErrors(valueArray, this._operatorList, this._bracketList));
17538
17544
  this._toggleError(checkInterpretationErrors(isInterpretationError));
17539
17545
  }
17540
17546
  _toggleError(errorModel) {
@@ -17583,9 +17589,9 @@ class FormulaEditorComponent {
17583
17589
  }
17584
17590
  this._selection = document.getSelection();
17585
17591
  if (this._selection) {
17586
- this._selection.removeAllRanges();
17587
- this._selection.addRange(this._range);
17588
- element.focus();
17592
+ // this._selection.removeAllRanges();
17593
+ // this._selection.addRange(this._range);
17594
+ // element.focus();
17589
17595
  }
17590
17596
  }
17591
17597
  _placeCaretAtEnd() {
@@ -17603,8 +17609,7 @@ class FormulaEditorComponent {
17603
17609
  }
17604
17610
  clickOut(event) {
17605
17611
  if (!this.eRef.nativeElement.contains(event.target)) {
17606
- const { value, visibleValue } = this._transformValue(this._inputValue, true);
17607
- this.updateValue(value);
17612
+ const { visibleValue } = this._transformValue(this._modifiedValue(this._inputValue), true);
17608
17613
  this.updateVisibleValue(visibleValue);
17609
17614
  this.isFocused = false;
17610
17615
  this._detector.detectChanges();
@@ -17618,7 +17623,7 @@ class FormulaEditorComponent {
17618
17623
  }
17619
17624
  }
17620
17625
  FormulaEditorComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.4.0", ngImport: i0, type: FormulaEditorComponent, deps: [{ token: DOCUMENT }, { token: i0.ChangeDetectorRef }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component });
17621
- FormulaEditorComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.4.0", type: FormulaEditorComponent, selector: "mrx-formula-editor", inputs: { fields: "fields", items: "items", disabled: "disabled", readonly: "readonly", placeholder: "placeholder", customClasses: "customClasses", invalid: "invalid", invalidMessage: "invalidMessage", checkInvalid: "checkInvalid" }, outputs: { changed: "changed", blurred: "blurred", modelChange: "modelChange" }, host: { listeners: { "document:click": "clickOut($event)" } }, providers: [{
17626
+ FormulaEditorComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.4.0", type: FormulaEditorComponent, selector: "mrx-formula-editor", inputs: { fields: "fields", disabled: "disabled", readonly: "readonly", placeholder: "placeholder", customClasses: "customClasses", invalid: "invalid", invalidMessage: "invalidMessage", checkInvalid: "checkInvalid", items: "items" }, outputs: { changed: "changed", blurred: "blurred", modelChange: "modelChange" }, host: { listeners: { "document:click": "clickOut($event)" } }, providers: [{
17622
17627
  provide: NG_VALUE_ACCESSOR,
17623
17628
  useExisting: forwardRef(() => FormulaEditorComponent),
17624
17629
  multi: true
@@ -17637,8 +17642,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.4.0", ngImpor
17637
17642
  }] }, { type: i0.ChangeDetectorRef }, { type: i0.ElementRef }];
17638
17643
  }, propDecorators: { fields: [{
17639
17644
  type: Input
17640
- }], items: [{
17641
- type: Input
17642
17645
  }], disabled: [{
17643
17646
  type: Input
17644
17647
  }], readonly: [{
@@ -17653,6 +17656,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.4.0", ngImpor
17653
17656
  type: Input
17654
17657
  }], checkInvalid: [{
17655
17658
  type: Input
17659
+ }], items: [{
17660
+ type: Input
17656
17661
  }], inputElement: [{
17657
17662
  type: ViewChild,
17658
17663
  args: ['inputElement', { static: true }]